When the player exits water while drowning, the breath bar slowly but surely increases until it's full. This has been a thing since 1.13 and not only this works for players but also for most mobs, except for fishes, squids and dolphins, which resets when they enter water.
The steps to reproduce is quite straightforward: Copy the below setup (the dispenser contains a water bucket), then spawn fish, squid or dolphin in the cage, when the fish, squid or dolphin takes damage, press the button. You will notice that the fish, squid or dolphin doesn't take damage for a while.
You can also try the same setup for another mob or a player, except there's water in the cage and the dispenser now contains an empty bucket instead of the water one. You will notice that when the button is pressed, that mob or that player takes damage almost instantly just like what you expected.