The short answer
No single person invented the gyro compass. Two engineers, Hermann Anschütz-Kaempfe in Germany and Elmer Sperry in the United States, developed practical gyrocompasses in the early 1900s, working largely separately. Their work built on the gyroscope, which physicists had studied for decades before.
Foucault and the gyroscope
The French physicist Léon Foucault showed in 1852 that a spinning gyroscope could demonstrate the rotation of the Earth, and he is credited with naming the device. That demonstration pointed the way toward using gyroscopes to find north. It did not produce a working navigation instrument, though. That step came later, from engineers who had to solve problems of damping, levelling and reliability.
Anschütz-Kaempfe’s design in Germany
Hermann Anschütz-Kaempfe worked on a north-seeking gyroscope in Germany in the early 1900s. His approach used a gravity-based control to keep the rotor’s axis close to level, so that Earth’s rotation could bring the axis into line with the north-south direction. He developed the design into a commercial instrument, and his company later produced gyrocompasses for ships.
Sperry’s development in the United States
Elmer Sperry was an American engineer already known for gyroscope work, including gyroscopic stabilizers for ships, when he turned to the gyro compass. He developed his own design at around the same time as Anschütz-Kaempfe, and his company also supplied gyrocompasses to navies.
Why the credit is shared
Each man developed and patented his own designs, and later engineers refined the idea further. Improvements to damping, to the way the rotor was supported, and to the correction of errors caused by a ship’s speed and course all made gyrocompasses more practical. No single moment or person settled the question of who invented the gyro compass, so the credit is usually given to both men.
Why the gyro compass mattered
A gyro compass gave navigators a north reference that was not affected by the iron in a ship’s hull or by electrical equipment on board. For large ships and, later, submarines, that made a real difference. A magnetic compass was still kept as a backup, but the gyro compass became the main reference on many vessels.
If you want to understand how the instrument actually works, the gyro compass working principle is the next step. It depends on the same spinning-rotor physics that Foucault demonstrated, applied to Earth’s rotation.