This bug is the cause of MC-242348.
It has been a well-known mechanic since 1.13 that /setworldspawn will allow players to respawn as close to the set y value as possible, instead of on top of the highest block (like in 1.12). This works regardless of the spawnRadius set. From my brief testing, it seems to require at least a 1x3 location at any y value. If that is not met, the player is respawned at the next highest block.
This behavior has been reverted to 1.12 behavior sometime in the development of 1.18 (which is unfortunate considering the stunning new cave generation making underground spawn points more enticing). /setworldspawn will now always pick the highest block in the column (including leaves, unlike 1.12).
Steps to Reproduce:
Open a world between 1.13 and 1.17.1 and another in 1.18.1 (and another in 1.12 if you wish to compare)
/setworldspawn
/fill ~-20 ~10 ~-20 ~20 ~10 ~20 minecraft:stone
/kill and respawn
Repeat at any y value of your choosing with at least 1x3 space to spawn. Invalidate spawn location and the 1.13 - 1.17.1 game will pick the next highest valid location to respawn the player.
It's worked this way for 3 years. You probably should reopen this.
The previous report was closed as "Works As Intended" because the assignee was under the impression that it has always worked that way stating, "This is a well-known mechanic." I am pointing out that it has not worked that way for 3 years. The previous report did not go into that detail so I opened a new one rather than comment on a dead report.
Did you even try in 1.13 - 1.17? They clearly do not act that way. I can make you a video of each version if that would convince you. 1.18 reverted the behavior.
You two clearly did not read my bug report. I am well aware that it duplicates MC-243079 and stated why I created this one. It follows that if I know the bug report exists, I also know how to use the search feature.
Can confirm that it also affects 21w17a
Caused by MC-243079; reverted 1.13 - 1.17 worldspawn behavior to 1.12 behavior.
To clarify the mechanics: 1.12 respawn picked the highest block to spawn the player, but ignored leaves unless there was a solid block beneath. Since 1.18 no longer respects y value for /setworldspawn (more info in MC-245811), the behavior was reverted to 1.12 but without the check for a canopy. Reproduce: /setworldspawn beneath leaves and /gamerule spawnRadius 0 (for convivence) then /kill. You end up on top.
If they reopened and fixed MC-243079, then this bug would be resolved as well.