If you stand on a block which has a door, closing the door can cause you perform the swimming animation. This also happens with fence gates and trapdoors.
There are also other scenarios that will cause the player to perform the swimming animation:
Player gets crushed by falling anvil
Player uses bone meal on bamboo while they are standing inside that block.
Sometimes happens when the player stands on a shulker box while rapidly opening and closing it.
Related issues
duplicates
Attachments
Comments

[media][media][media]

Duplicates MC-147266, I've updated that ticket to include the mentioned scenarios.