A new post on the Official TF2 Blog explains this quite well:
How do respawn waves work? Is my respawn time affected by my performance? Why do they exist at all?
Respawn waves occur on regular intervals, based on the map settings. Most of our maps use a 10 second respawn wave time. That 10 seconds is then modified by the map state, generally reduced for the team that controls the most capture points. Each team's respawn wave time is then scaled down if the team has less than 8 players in it, to a minimum of 5 seconds if team has 3 or less players in it. When you die, you are assigned to the respawn wave after the next one. So if the respawn wave time is currently 10 seconds for your team, you'll respawn somewhere between 10 and 20 seconds from your death. Your individual performance doesn't affect your respawn time in any way.
We found respawn waves were a good solution to several problems.
* They provide a reward for the team that's doing well, in that if they wipe out a significant amount of the enemy team they're rewarded with a short grace period in which they can achieve objectives. Without them, we found teams felt like they'd been penalized when they cleared the enemy off the last capture point, only to have them all return immediately.
* They group respawning players together into squads, increasing the chances of strangers working together, or at the very least, moving to the frontline while maintaining some proximity to one another. Strangers aren't pushed together into groups when everyone respawns instantly, and we've seen that proximity to team mates is a fundamental requirement for impromptu teamwork.
* They provide some ebb & flow in the pacing of the battle. Without some cooldown inbetween the moments of intense combat at the frontline, many players felt fatigued much more quickly. In particular, some attack/defense maps feel almost completely static without respawn waves. That lack of progress, in either direction, was a big factor in players finding the gameplay monotonous.
* The spectator camera seen while waiting to respawn gives players some time to observe their team mates. This provides a minor help to teamwork, allowing players to see what other members of their team are up to. More importantly, we've seen that new players learn a lot of advanced techniques by spectating better players. This is one of the reasons why the spectator camera tries to find a team mate who's playing the same class as you.
Obviously, there are other solutions to these problems, but respawn waves do a good job across the board.