Disclaimer - this only happened once, so it is potentially rare-ish to encounter during normal gameplay, but testing could probably reproduce this fairly reliably. A baby villager grew up in a nearby house, and its head clipped into the ceiling, causing it to get stuck, and rapidly take damage and die.
I have tried to replicate this bug in a test world where I summon a bunch of baby villagers. age:-1000 in thir own 2x1 cell with a bed. I set the time of day = 0 because baby villagers usually jumps on the beds at dawn. The cieling in the cells are 3 blocks above them. The majority of the baby villagers are growing up while jumping in the bed and a lot of them clip through the cieling and take damage. But they fall down again immediately after and dont get stuck in the cieling and die. I have included a screenshot.
If the cieling height is only two blocks then of course the villagers will be stuck if they grow up while standing on the bed, since the free space above the bed is less than 2 blocks.