Sefer Chofetz Chaim chapter 10 halacha 5

One is allowed to speak out against those who speak lashon hara if they meet the rules set down at the beginning of the chapter. Being that only the real reason to publicize the people speaking lashon hara is to warn people to start away of the sim and speak of it’s severity, therefore you can only speak out about those who speak lashon hara if the ones who lashon hara was spoken about knows what happened, if he doesn’t then because he’ll find out since word travels then one cannot speak out about it because it will most likely lead to more argument and is considered rechilus. One wouldn’t be able to first tell the person spoken about since it will lead to more arguments and is considered rechilus, even if the subject of the lashon hara was a great sage. But if a great sage or any upstanding Jew of society was spoken badly about by a low life then people can warn others of the severity if speaking lashon hara about rabbis even if the rabbi did not find out about it because telling others isn’t rechilus, and in most circumstances the rabbi won’t escalate a fight but of course each case should be judged by itself.

Proof to this halacha is from a gemara in Moed Katan 16a (according to the Rosh) which says that if not for the fact that the person was a messenger of the court he would not have been allowed to tell Moshe Rabbeinu that Dasan and Aviram was saying lashon hara about him by the rebellion of Korach. Even though Moshe Rabbeinu was the greatest leader of the Jewish people, and they were incredible lowlifes, having told on Moshe to pharaoh in Egypt when he killed the Egyptian, almost having him killed, and trying to collect manna on Shabbos, still in all it would have been rechilus to tell Moshe the lashon hara they spoke about him if not for the fact that this was a messenger of the court and it was his job to ensure law and order is preserved.