The player's previous gamemode is not saved correctly on the server.
Expected behaviour (behaviour in versions prior to 1.19.3):
/gamemode creative
/gamemode spectator
Press f3 + f4 (switches back to creative)
/kill or rejoin the world/server
Press f3 + f4 (switches back to spectator)
Observed behaviour (1.19.3+):
/gamemode creative
/gamemode spectator
Press f3 + f4 (switches back to creative)
/kill or rejoin the world/server
Press f3 + f4 (switches to survival)
Code analysis (yarn mappings):
ServerPlayerInteractionManager#changeGameMode (1.19.3):
[media]ServerPlayerInteractionManager#changeGameMode (prior to 1.19.3):
[media]The previous game mode being set in ServerPlayerInteractionManager#setGameMode is no longer being set to the existing gamemode but instead the previous meaning that this never changes - it is always null, unless the player had set their previous gamemode in a version prior to 1.19.3.
Duplicate of MC-259571; your report does have clear steps to reproduce and analysis though.
I'd suggest mods copy that over.