Well, we are assuming that the person who is betting on the underdog have complete knowledge before he is placing the bet on underdog team.
Without knowing the teams strength, the person won't know if the team he is betting is underdog or favorite. Sometime the big difference in the odds also tell this information but you need to be clever to find it out.
When they mess up though, they usually cancel the bets on that game. I have seen it before. Every once is a while you get lucky and get away with it but if the bookie was losing big amounts because of that game, they can always cancel the bets and say that it is their right to do so. They are not in the money losing business in the end. The players are.