When a village is fully populated and the villagers are sleeping (all beds are occupied), villagers may repeatedly attempt to sleep in an already occupied bed.
This bug took place in a man-made village. There were 17 villagers, but this bug happened with fewer. It's possibly more likely to happen in larger villages with lots of beds.
1. Locate/create a village
2. Make sure there is exactly one villager per bed in the village
3. Wait until nightfall, when the villagers go to bed, and make sure there is at least one unoccupied bed
4. If a villager is unable to find the open bed, they may repeatedly enter and exit other villagers' houses (or one house repeatedly) and target an already occupied bed.