If heat causes the magnet to lose its properties, how it is possible that the Sun has a magnetic field.
The magnetic field of the Sun has a different origin from the magnetic field of the magnets we all played with as children.
Magnets owe their magnetic field to a phenomenon called ferromagnetism. Electrons have an intrinsic magnetic field i.e. every electron behaves like a tiny bar magnet. In ferromagnets the unpaired electrons line up so their intrinsic magnetic fields reinforce each other and produce the large magnetic field of the magnet.
However the thermal vibrations in the magnet jostle these electrons, and if you heat the magnet to above a transition temperature called the Curie temperature the jostling becomes so great that it knocks the electrons out of alignment and the overall magnetic field disappears. The magnetism hasn't disappeared - it has just become randomised.
In contrast the magnetic field of the Sun is due to the currents inside. Any moving charge generates a magnetic field, and since the Sun is made of plasma there are lots of moving charges in it. The Sun's magnetic field is generated by the large scale flows of the plasma within it. These flows are driven by temperature differences, so in fact the Sun owes its magnetic field to its high temperature.
You don't have to go as far as the Sun to see this, because the same happens in the Earth's core. The temperature gradient from the centre to the outside of the core causes convection currents and this motion generates the Earth's magnetic field. This happens even though the temperature of the core is well above the Curie temperature.