The Earth behaves like a giant magnet, its invisible field lines stretch from the southern to northern pole.
When you turn the compass, the needle stays fixed to magnetic north, guiding you to true direction.
A magnetized needle feels torque, turning until it aligns perfectly with Earth's magnetic field direction.