Tested it, you do get XP as a spectator if you've spawned that round. And choose team and go back to spectator until you get into the winning team.
I just tested it as well. And you're right, you get xp as a spectator if you've spawned that round. HOWEVER, if the team that you spawned on loses, you lose your modifier at the next XP tick, even if you were spectating and get switched to the other team.
So basically, this glitch only works if you can switch to spectator, then switch to the other team before your team loses, which doesn't happen most of the time. It typically keeps putting you back on the same team. And spending all your time doing this, rather than helping your team, you're probably no more likely to get a modifier, unless you suck
REAL bad.