Players can use spectate mode and when they are done they will be forced teleported back to the location they started spectating and also set to the same gamemode as they were before.
It is also possible to set a timer for how long a player can be in spectate mode before being teleporting back.
Start and stop spectate mode /rspectate
/rspectate <PlayerName>