Villagers will sleep briefly after it is daytime if you take their bed while they are sleeping in it.
Steps to reproduce
- Go to a village
- Wait for nighttime
- Sleep in a bed occupied by a villager
--> Notice the villager tries to sleep in it after you wake up.
I have only ever seen it occur in survival mode, though it is likely it happens in any gamemode other than spectator.