An interactive gyro compass loads here. It needs JavaScript; the sections below explain everything it shows.
A rotor spinning very fast keeps its axis pointing the same way in space, however its mounting is turned. This gyroscopic rigidity is what a spinning top or a bicycle wheel shows. On its own, though, a free gyro would point at a fixed direction in space, not at north, and as the Earth turned it would seem to drift.
A gyro compass is made pendulous: weighted, or controlled, so that gravity acts on it whenever its axis tilts. As the Earth turns beneath it, its axis tilts, gravity pulls on it, and the rotor responds by moving sideways, precessing, towards the meridian. Damping stops it swinging past, and it settles with its axis along the north-south line, pointing at true north.
Settling takes time. After the gyro is started, or after its power has been lost, it needs several hours to come back to true north.
The ship's own speed and course, and its latitude, shift the point the gyro settles on slightly. The gyro is corrected for them, often automatically from the speed log and the GPS position.
The master gyro sends its heading to repeaters round the bridge and the steering position, and to the radar, ECDIS, autopilot, AIS and voyage data recorder. A gyro fault can take out the heading for all of them at once.