Any particular reason why you want to do this from inside the engine? In the game code you can simply call SetTeam(ent, "spectator") and be done with it.