When the high-pressure gas propelling the bullet bursts out into the water, the water gets thrust violently aside- as it also does as the departing bullet itself tears through the water.
This necessarily imparts kinetic energy to the water, which then ballistically expands outward (allowing the gas inside to cool down) until the pressure inside the expanding gas bubble falls to the saturation pressure of the surrounding water.
Then the resulting low pressure inside the (overexpanded) gas bubble reverses the expansion of the bubble and it then begins to collapse as the water vapor inside it condenses.
The combustion gases from the bullet explosion- which do not condense- are then suctioned up into the cavitation wake left behind by the bullet and the gas bubble near the muzzle contracts quickly.
We now have the pushed-aside water being propelled back together again, and as the bubble shrinks two things happen: the imploding water mass picks up kinetic energy and the pressure inside the bubble starts to go positive again since the undissolved gas inside has no time in which to dissolve into the surrounding water.
The pressure in that gas increases very rapidly as the bubble contracts- far too rapidly for the resulting temperature rise inside the bubble to heat the surrounding liquid- and the kinetic energy of the water surrounding the bubble collapse gets stored as potential energy in that gas, which is far more compressible than the water is.
Because of that, the compressibility of the water itself can be omitted from the analysis.
So at the moment of total collapse (bubble volume ~ zero but not quite) the water squashes the air which then bounces back and the bubble re-expands ballistically, overexpands, contracts again and so forth.