If there are 2 blocks above a bed, players can't sleep, but villagers can.
To reproduce this bug, blocks their bed with 2 blocks, then sets the time to night to make them enter their house and sleeps on their bed. If the player tries to sleep, he/she can't because it's obstructed.