Hilchos Lashon Hara chapter 10, section 3
This only applies if the person was better than the wrongdoer, but if he is a sinner like him and does the same sins, he may not publicize him. For such a person’s intent is not for benefit or due to fear of G-d, but to rejoice at his downfall and embarrass him. It already says regarding this, I will punish the house of Yehu for the blood of Yizrael (Hoshea 1:4). Even though Yehu did a mitzvah by cutting off the house of Achav in Yizrael, for so he was commanded by a prophet, and he received in return kingship for four generations as it says, Because you did My heart’s desire to the house of Achav, sons of the fourth generation will sit of you on the throne of Yisrael (II Melachim 10:30), nonetheless, he was punished because he too had many sins.