When you set your respawn location with either a bed or an respawn anchor and dies there is a check to check if the bed / respawn anchor still exists.
The "bed / respawn anchor check" checks both for beds and respawn anchors no matter what dimension you are trying to respawn in. Meaning that if you go into the nether and place a respawn anchor, set your spawn point and then replace the anchor with a bed the next time you die you will respawn in the nether beside the bed.
You will only be able to spawn beside beds in the overworld.
You will only be able to respawn beside respawn anchors in the nether.
Place respawn anchor.
Fill anchor with glowstone.
Right click the anchor to set respawn point.
Break the anchor.
Place bed in same location.
Next time you die you will respawn beside the bed in the nether.
Right click the bed to set respawn point.
Place anchor in the location the bed's head was at.
Fill anchor with glowstone
Next time you die you will respawn beside the anchor in the overworld.