The villagers sleep and for no reason start to get out of bed in a loop. Sometimes they resleep but sometimes they get stuck outside and make the bed unusable for the one who was inside, but another villager can sleep in. This often happens when they get hit or a transparent block is above their heads.
To reproduce this bug just:
Do as in the photos
place a carpet above the location of the head
Line up the beds and block the exits so that only the location of the head remains
Reason could be:
No enought space on the top of the bed
Bloc placed above head's space.
Hit box buggy
AI is buggy
I know that this bug only appears in a specific situation. Being afraid by a zombie does not cause any problem to sleep/leave the bed. So i don't know.
Duplicates MC-152084