A gyroscope works due to precession. Precession is the movement of one axis around another axis on an object that is spinning, which changes the direction of the first axis. This movement of the axis is what creates the motion of the gyroscope.
The precession of a gyroscope is based on Newton's first law, which states that a body in motion stays in motion at the same speed in a straight line until another force acts upon it. When a gyroscope is moved, the axle has a force applied to it. This forces the axle to move in a direction in a straight line, but because of the gyros in the device, the gyroscope rotates while trying to move in that same direction.
Different sections of the gyroscope begin to rotate at 90 degrees to the side while still trying to maintain their direction. The axle is constantly being changed and impacted by another axle spinning around it, forcing the gyroscope to move in its direction of precession. This process of precession continues until the original force that caused the movement of the gyroscope is cancelled out. Cancelling out the original motion causes the axle of the gyroscope to hang in the air, which explains the behavior of the device.