The extremely fast spinning gyro remains in the same orientation in space as the instrument case moves around along with the instrument panel and the whole aircraft. The difference between the orientation of the gyroscope and the casing is mechanically or electronically transformed to display the orientation of the plane
The stabile orientation of the gyro is achieved by the gimbals: each axis has its own gimbal that will allow (almost) frictionless movement with respect to that axis. However the gimbals are actually not free to do what they want so to speak. They are dependent on each other by stacking: each axis/gimbal is dependent on a higher level one that it attaches to. This will in some instances lead into an interesting situation called gimball lock. This video describes the phenomenon: