How does your experiment work? It’s all about buoyancy.
Gravity is always pulling an object’s mass down. However, whatever that object is on, is pushing back up on the object. Buoyancy is the force of that upwards push. It equals the the weight of the water (or other liquid) that is displaced and pushed out of the way by the object. When something is floating, the buoyant force is the same as the weight of the object.
When a Cartesian diver floats, a little bit is above water. The part underwater with the trapped air is displacing enough water to equal the weight of the diver. It’s counteracting gravity.
Some things you can compress and squeeze. You can sit on a suitcase and squeeze in things to shut it that otherwise wouldn’t have fit. You can’t do that with liquids. Squeezing on the water bottle moves the water, it doesn’t compress it and make it smaller. The moving water pushes on the air in your diver. Air, as a gas, does get compressed. If you used something like a medicine dropper that is clear, you’d be able to see the water level changing on the inside as the air space got smaller.
Compression means squeezing in. So when the air is compressed, it’s taking up less space. That means the volume of the diver decreased. When there is less volume in the water, it’s displacing less water. The displaced water equals the buoyant force upwards, so there is less force pushing up. When that force is less than the diver’s weight, the diver sinks.
When you let go of the bottle, the air expands, the diver takes up more volume, displaces more water, meaning there’s more buoyant force pushing up, and the diver floats.
When it’s floating, the diver’s weight equals the buoyant force.