Answer:
When lava hardens into rock minerals are formed. These minerals are the magnetic crystals then align themselves to the magnetic field of the earth.
Step-by-step explanation:
They get locked in the magnetic field as very small tiny compasses that is crystals behave as magnets.
These crystals loses its magnetism only if it is heated above the curie point which is the temperature at which the magnet loses its magnetism.