function Trefrig = Trefrig(state.time)
thermalBC(thermalmodel,"Edge",7,...
"ConvectionCoefficient",hrefrig,...
"AmbientTemperature", @Trefrig)
First of all: when you define a function then the list of parameters must be strictly unindexed variables. You cannot designate the field of a structure to receive data.
Second of all, attempting to assign the output to the same name as the function would be an attempt to convert between the name representing a function and the name representing a variable, and is no longer permitted.
Thirdly: neither thermalmodel nor hrefrig are defined inside the function.
Fourthly: you are passing @Trefrig as the AmbientTemperature parameter. That is a handle to the exact same function you are defining. The intent is almost certainly that the function handle would be invoked -- but invoking it would cause termalBC to be called again, which would pass in @Trefrig which would lead to @Trefrig being called again, which would call termalBC again which... If you are going to deliberately construct recursive code, you need to ensure that you have an escape condition before blindly calling the function again.
Fifthly: the AmbientTemperature parameter accepts scalar numeric values only, not a function handle.