/scoreboard objectives add death deathCount
/scoreboard objectives add respawn dummy
/execute as @a at @s[scores={death=1}] run gamemode spectator @s[scores={death=1}]
/execute as @a at @s[scores={death=1}] run scoreboard players set @s respawn 140
/scoreboard players reset @a death
/scoreboard players remove @a respawn 1
/execute as @a at @s if score @s respawn matches 0 run gamemode adventure @s
Note: if you want to have the players respawn at a certain location, then you can just have a command that says /execute as @a at @s if entity @s[scores={respawn=1..}] run tp @a COORDINATES_HERE