If metal expands when heated, how does heating a bolt loosen it?
The answer is surprisingly simple: the bolt expands, but the nut expands more.

What is happening here is good old thermal expansion:


The bolt is heated and expands outwards, its radius increasing
The nut is heated and... expands outwards, its radius increasing


Now, since the nut's radius is slightly greater than the bolt's, and since the increase is proportional to the rest length, the nut expands a little more.

Iron has a thermal coefficient in the 10-5 / K ballpark. It means that for each 1 K increase in temperature you have an increase in size of 10-5: a 1 m rod becomes 1.00001 m long.

If your bolt has r = 1.5 mm, and the nut has R = 1.501 mm, what happens is temperature is increased of 500 K? Well:


r = 1.5*(1+500*10-5) mm = 1.5075 mm
R = 1.501*(1+500*10-5) mm = 1.508505 mm


As you can see, before heating R - r = 1 μm, while after R - r ≈ 1.001 μm. It increased!

Please note my numbers are quite wild and used just to make an example. I am sure that I got the starting values wrong, but I hope they help to get the message across anyway.