This is a bug related to MC-23940 but it is not a duplicate. I understand that if the bed is surrounded by transparent block (on ground level) will not allow the player to spawn next to bed when killed. However, If there is one block at ground level that is opaque, and on top of this block are two transparent blocks. (ex: two glass block vertically placed on top of a wool block), then sometimes the player will spawn inside the glass.
The bug i am really trying to point out is that "the player will spawn on the roof if killed in this situation." It is like system search for the next spawning point available on top of bed.
1st picture shows the bed where i sleep- the bed surrounded all by transparent block except one block, which is the block beneath the glass pillar
2nd picture shows i wake up in the glass pillar
3rd picture shows that i spawn on top of the glass pillar because i suicided (which means i spawn on top of the roof)
Duplicate of MC-9529
If you have not, please use the search function in the future, to see if your bug has already been submitted. If you could not find the original report, please comment with the keywords you searched for.