An effective counter to spawn camping?
Solution 1:
Spawn-camping is one of the riskier strategies a team can employ - you are fighting the enemy team outside a one-way door which only they can open, and behind which is an infinite supply of health and ammo that only they can access. It only works if the team being spawn-camped is so uncoordinated that they would be losing badly anyways even if not being camped. The team inside spawn actually has the advantage of being right next to their resupply cabinets - they can change classes and loadouts and refill ammo and health at will.
Breaking even a serious spawn camp merely requires some coordination. Running out one at a time is not going to work - they will have time to repair their sentries and reset their sticky traps in the time it takes you to respawn. Have a medic (preferably two or three - they probably have at least one medic) build uber (normal uber) on some scouts / soldiers / demomen who can inflict self-damage to speed up the process. Deploy the ubers on some heavies right out of the gate and clear any sticky traps and other immediate threats that may be present. Have the demomen and soldiers follow behind to destroy sentry nests and teleporters. Once you do that there should be no more spawn-camp. Kill as many enemy players as you can and go for the objective to make up for any lost time.
If you are playing on a public server and your team is uncoordinated enough to get spawn-camped, it is probably game over. There is very little you can do alone, unless you are a very good spy (but remember, even if you walk out cloaked, they can see the door open). If you feel up to it, try coordinating / organizing your team a bit via chat (text or voice). Nobody likes being spawn-camped so odds are if someone takes charge people will follow.
One last note - most maps have more than one spawn exit (typically 3). If they aren't camping all exits simultaneously you can just sneak out and let the campers waste their time.
Solution 2:
If your team has at least a few smart players and you're getting destroyed hard enough, the best idea is probably to just sit in spawn and charge Über, then have everyone bum rush out the doors while it's being deployed. If you're feeling lucky you can try to get multiple Übers or an Über-Kritz combo going. Make sure that you try and stay out of line of sight and splash from the door, because you know there'll be that one guy who keeps opening it.
Once you have your charge, hit the button before the door actually opens to minimize the probability that the server decides the enemy stickies/Kritz/Phlogs went off first. Focus all your team's firepower on the Sentry and Teleporter (if they have them), followed by the enemy Engineers and Medics. If your team has a clue, the rest of the enemy team should thin out pretty quickly after that, or at least get thin enough that you have some territory back.
It would also be helpful to try having a Dead Ringer Spy get out the door, fake a dumb Scout/Engineer/something death, and stab at least one guy just before you launch the party. That way people will hopefully turn towards the Spy while you have your fleet barging in. (Exception: If there's an Engineer setup camping you, it's far more important to get the stuff sapped then to stab anyone.) Of course by the time you get your charges up, you'll probably have at least two GENIUS SPIES trying to do this and so letting the spy-checkers get wise. Depending on the situation, a Bonk Scout can also provide a distraction.
If your team is particularly bad, it's possible to get spawn-camped even without the aid of a Sentry or stickies (say, just a smart Heavy-Medic pair). You don't really need to charge Über for this, you just need to get people to stop exiting spawn one at a time and instead charge out in unison.
Solution 3:
Having a well-experienced Scout who has a Bonk! Atomic Punch can help when you ca kill one or two enemies, but there are still too much to exit spawn. Once the Scout can get out of the campers, he can pick off valuable targets, such as a heavy/medic pair, an experianced demo. He can also use this method to absord sentry fire. When the sentry is firing at him and when he grabs the attention of a few players, he can lure them away from spawn, so your team can get out and take revenge.