A compass always points north because Earth's iron core creates a magnetic field that attracts the compass needle to the North Pole. However, a compass doesn't point directly to the North Pole; Earth's magnetic field is a little offset. This deviation from true north is called declination.
The working theory is that the heat from Earth's liquid molten core and the rotation of the planet create the magnetic field. Since Earth is so large and the magnetic field very weak, a compass must have a lightweight magnet and a bearing that is frictionless to detect and point to the north.