When a respawn anchor is covered on all sides (including diagonals) either with solid blocks or air, it will count as being obstructed, even if there would be space above the anchor.
MC-175206 Respawn anchors in midair are considered obstructed
MC-175759 respawn anchors with no blocks around it don't work
MC-175166 You respawn next to the respawn anchor instead of on top of it
MC-175241 Carpets obstruct respawn anchors
MC-175245 The player's spawn point is reset to the world spawn point if the bed or respawn anchor is obstructed