How does liquid iron create a magnetic field?
It seems your question assumes that Earth magnetic field is caused by natural magnets inside the Earth. Instead, the magnetic field comes from the movement of charged particles.
Any electrical charged particle in movement generates a magnetic field (see Biot-Savart law and Ampere law), hence, thanks to the movement of particles in a liquid mantle we have a magnetic field. Obviously, particles must have electrical charge, which is more common in metals.
If mantle turns solid, movement is gone, and the magnetic field reduces its strengh.