Pumice is a magmatic rock caused by very violent explosive eruptions. If you look closely at a small pumice stone you will see very small round holes that are not connected to each other and therefore do not allow water to penetrate the rock.
This makes it a rock with a lower density than water, with the result that it floats.
Pumice is formed during a highly energetic and explosive event when there is a rapid loss of pressure in the system.
In particular, when the solidified rock cap of the surface part of the conduit is ripped apart by an explosion due to accumulated gas, a decompression is created in the conduit that reaches the magma chamber below.
This fast decrease in pressure allows all the gases that were dissolved in the magma to form small bubbles, which by joining together, will form magma foam. This foam is then brought to the surface at high speed, dispersed in the eruption cloud and falls back into the surrounding area.
The mechanism is the same as when you uncork a bottle of sparkling wine, if the foam it produced after you removed the cork were to freeze.