This is a fairly big issue to explain, with a lot of aspects so here goes
Normally when you sleep thru the night in a bed, it will always kick you to the north west corner of the pillow, if it can. That north west corner is now your respawn spot, and you will always respawn right there. Once you die and then respawn on that north west corner, the game thinks that area is safe for spawning.
What you can do from this point is build a pillar to sky limit on that north west block, and the next time you die, you will spawn on top of that sky pillar. At Y255 if you made it that tall.
You can also remove all the blocks on the north west corner going down to bedrock, and when you respawn at your bed you will instantly fall to your death.
So basically after you respawn at your bed once, it stops making sure where you spawn is actually safe. Leading to extremely easy ways to troll players, and get into infinite death loops.
Footage of this bug and how to reproduce. Skip to 3:37