A gyrocompass is essentially a gyroscope, a spinning wheel mounted on gimbals so that the wheel's axis is free to orient itself in any way. Suppose it is spun up to speed with its axis pointing in some direction other than the celestial pole. Because of the law of conservation of angular momentum, such a wheel will maintain its original orientation. Since the Earth rotates, it appears to a stationary observer on Earth that a gyroscope's axis is rotating once every 24 hours. Such a rotating gyroscope cannot be used for navigation. The crucial additional ingredient needed for a gyrocompass is some mechanism that results in applied torque whenever the compass's axis is not pointing north.
One method uses friction to apply the needed torque: the gyroscope in a gyrocompass is not completely free to reorient itself; if for instance a device connected to the axis is immersed in a viscous fluid, then that fluid will resist reorientation of the axis. This friction force caused by the fluid results in a torque acting on the axis, causing the axis to turn in a direction orthogonal to the torque (that is, to precess) towards the north celestial pole (approximately toward the North Star). Once the axis points toward the celestial pole, it will appear to be stationary and won't experience any more frictional forces. This is because true north is the only direction for which the gyroscope can remain on the surface of the earth and not be required to change. This is considered to be a point of minimum potential energy.
Another, more practical, method is to use weights to force the axis of the compass to remain horizontal with respect to the Earth's surface, but otherwise allow it to rotate freely within that plane. In this case, gravity will apply a torque forcing the compass's axis toward true north. Because the weights will confine the compass's axis to be horizontal with respect to the Earth's surface, the axis can never align with the Earth's axis (except on the Equator) and must realign itself as the Earth rotates. But with respect to the Earth's surface, the compass will appear to be stationary and pointing along the Earth's surface toward the true North Pole.