Either small leaks of changes in atmospheric pressure.

>**Bubbles can form from high elevation or exposure to cold temperatures, which cause the liquid to contract, leaving an air bubble behind. Usually, the bubble will disappear when the compass is returned to sea level and/or room temperature.** If it doesn't, place it in a warm spot-like a sunny windowsill-so the liquid can heat, expand, and return to it's normal volume.

[Compass Bubbles][1]

>A compass is usually filled with water or compass oil, which is a mixture of water and mineral spirits. Bubbles usually emerge in compasses as a result of drastic atmospheric pressure changes or a slight leak in the housing material.

[Source][2]

>Generally, magnetic compasses are designed to not have a bubble; if you see a bubble, the chances of a leak is high. This may seem unlikely to you, because you may not have noticed any fluid escaping from the compass. 

>...

>Your compass has most likely developed a very small leak, which has allowed some fluid to escape. When you observe the bubble in the morning, your compass is cool and the missing fluid has caused a bubble to form. As the temperature rises, the fluid expands, thereby taking up volume and making the bubble disappear. 

[Source][3]

It is possible to keep this from happening.

>A method of preventing air bubbles in a compass equipped with fluid expansion capability, **wherein a compass unit is assembled with a fluid expansion diaphragm; the compass unit is filled with fluid expanding the diaphragm, and sealed while maintaining the diaphragm in its expanded state for preventing air bubbles in reduced pressure and/or reduced temperature conditions,** without significantly changing the basic structure of the compass.

>...

>Description

>FIELD OF INVENTION

>This invention relates to an air bubble free compass.

>BACKGROUND OF INVENTION

>Some compasses are designed with a housing which includes a neoprene expansion diaphragm that allows for expansion of the damping oil when the compass is subjected to heat which can occur when the compass is in the sun on the bridge of a ship. The diaphragm expands and contracts maintaining proper fluid pressure in the compass unit.

[Air bubble free compass and method of manufacturing same][4]


  [1]: https://www.backpacker.com/gear/compass-bubbles
  [2]: http://A%20compass%20is%20usually%20filled%20with%20water%20or%20compass%20oil,%20which%20is%20a%20mixture%20of%20water%20and%20mineral%20spirits.%20Bubbles%20usually%20emerge%20in%20compasses%20as%20a%20result%20of%20drastic%20atmospheric%20pressure%20changes%20or%20a%20slight%20leak%20in%20the%20housing%20material.
  [3]: http://www.mrs-marine.com.my/index.php/technical-info/magnetic-compass-frequently-asked-questions
  [4]: https://patents.google.com/patent/US5469631