There are some conversations you can legitimately listen in on and contribute to, namely the pleasant, harmless sort. If the people next to you on the bus are chatting about the weather, I think you might mention that a high-pressure front is supposed to move in on the weekend, or if there are some strangers in line with you at the movie are trying to decide what restaurant to go to, it would be acceptible to excuse yourself for eavesdropping, and suggest your favorite Indian place.
Butting in to correct a stranger on anything but the most trivial topics, though, is just rude. There’s a time and place for fighting ignorance. The only exception would be to protect someone from danger. If you overhear someone say, “I hear that the best way to clean mildew is with an equal mixture of ammonia and bleach!” then you would be right to jump in—after apologizing profusely for having overheard, of course.
If people are arguing heatedly, I think it’s politest to pretend that you can’t hear. They really oughtn’t quarrel in public, but sometimes Emotions Run High, and I hope that others might extend me the same courtesy if I should have a lapse. More to the point, I certainly don’t see the attraction of involving yourself in someone else’s messy scene—or causing such a scene, as in the OP’s example of hearing someone criticizing a friend of yours. In that case it would take inhuman willpower to ignore what is being said, but getting huffy with strangers over a conversation that does not include you is Just Not Done, so IMHO you should just Bite Your Tongue and Fume Silently. On the other hand, I think you have every right to report what you heard to your friend if you think they ought to know—the gossipers were indiscreet, and you are not under any obligation to hold their remarks in confidence.
If someone says something broadly offensive in public, I really don’t see the benefit of upbraiding them for it, though a dirty look might be in order. If they’re the sort of person who would use an ethnic slur, for example, within earshot of strangers, they are are probably not the sort who would feel shame upon being called on it. If they’ve just slipped up and forgotten themselves, a dirty look should be sufficient to remind them where they are.
If the conversation is intolerable in content and unignorable in terms of volume, I think that one would still do best to ignore the former, and speak to the offending parties about either lowering their tone or taking the discussion to a more appropriate venue.
Restaurants are a special case, in my mind. I think that a table with a party gathered around it, backs to the rest of the world, defines a certain zone of privacy. IMHO, what they’re eating, any personal items they might have with them, and any conversations they’re having are None of Your Business. Naturally your eye might fall upon them, and you will accidentally overhear snippets, but you should do your best to ignore them. Even if you should come across some friends of yours dining, you should just give a friendly greeting and move on unless they invite you to sit down and join their table.