Now, this obviously doesn't apply to competitive matches, but it's a problem that you'll face in just about every pub. And no matter how skilled you as a player are, it's probably the single most frustrating, guaranteed-to-lose-your-temper things you'll face in this game.
You can usually spot a game in which teams are stacked by the difference in point margins, as shown below:
As you can see, the blue team has totally wiped the red team. 4-0 is a pretty big margin to win by, especially in 32man pubs. Additionally, if you check the lowest scoring players on each time, you can see that the "lowest common denominator" has quite a big skill gap, yet another indicator that not everything is fair.
So what do you do in this situation?
Obviously, you could just leave, or join the stacked team. But if you do join the underdogs, here are some tips:
First: Consider the type of map. Is it 5CP (ex// badlands, granary)? Then going engy isn't going to help your team; it'll just prolong your defense. Instead, considering going demoman or soldier to bolster the sheer offensive force. However, don't plan on doing so as a sword n board or black box player, because you won't be as effective.
Second: How many medics does your team have? Sometimes, especially in 16v16 games, one extra medic helps everybody more than any other class could. It is as the immortal spock once said, "the good of the many outweigh the good of the few." Even if you're a great offensive player, you'll pick the average level of your entire team up by playing medic competently.
Third: Do you have a mic? Use it. In most pubs, only half the team actually knows what the objective of each map is. Having one person acting as the "team announcer" can do wonders. This can be any player, but it's often most helpful if this person is a medic who can coordinate pushes, kritzes, and ubers. If you have a mic, call out everything you see--that spy you saw out of the corner of your eye might not get away if you tell a teammate about him.
Fourth: Sometimes, ignoring class balancing is fine. It's often extremely tempting to play the classes there are none of on your team, so that you stand out more, or "fill in the holes" in your team's offense/defense. However, in most cases, you don't need that pyro or spy. Oftentimes, having a team of 2-3 soldiers or demomen is more than adequate, because these classes are well rounded and prepared for just about every situation. More situational classes, such as engineer or scout, aren't always as effective.
Fifth: Bring a buddy! If you and a friend can set up a heavy/medic or soldier/medic pair, you can oftentimes become a coordinated force that can sway the tide of battle in your team's favor. Don't be afraid to push on your own, if you know a medic has your back.