Dear Student
The alignment of a freely suspended magnet is influenced by the earth’s magnetic field. Our earth is assumed to have a strong magnet with its south pole near the geographic North Pole and the north pole of the magnet near the geographic South Pole.
This is why when a magnet is freely suspended; the north pole of the magnet points towards the geographic north pole of earth and south pole of the magnet points the geographic South Pole.
Same is the case with needle and magnet. Like poles repel each other and unlike poles attract each other.
Regards