We associate compasses with pointing north, but the direction of arrow can be manipulated. When the permanent magnet is present, it overrides Earth’s magnetic field because it’s stronger. The closer the magnet is to the compass, the more powerful the effect.
No one knows for certain what generates Earth’s field, but one widely accepted explanation points to the currents and turbulent activity happening inside the molten iron core of the planet. The true north and south poles of the field move around and can even reverse periodically. Meaning the compasses of the past might be pointing a different direction than the compasses of the present and future.
To learn more about how compasses were invented and used in the past read up on the Early Chinese Compass.