Sefer Chofetz Chaim chapter 10 halacha 3 and 4

Halacha 3: Even if you try to meet all the prerequisites to speak out against a perpetrator in a legal way, but if you are the same type of sinner as the perpetrator then you can’t say a anything because we assume you aren’t speaking out to help anyone besides yourself, to make the perpetrator look back and yourself look good. For example, a thief can’t rattle on another thief, or a business swindler can’t rattle on a business swindler, or a drug addict can’t rattle on another drug addict who might be selling drugs to others etc. We see this in Navi that Yehu was accountable for killing the house of Achav even though the Navi said to do so because they were an evil kingship and Yehu was rewarded for 4 generations of kings in his family for following the prophet’s word but because he wound up following in their evil ways when he became king over Israel then he became accountable for killing them. So to you can’t speak lashon hara about someone if you yourself have the same fault because you are just making yourself look good by speaking out against him, which is just covering your tracks not the intent to help the situation.

Halacha 4: Because your whole intent must be for the good, for example to help the victim then you can only tell people who will help the situation. But not just police, it could mean telling doctors or psychologists what happened to help the person damaged or embarrassed to get healthy again, or anyone one else who can fix the situation. However, it is also permissible to tell anyone else with mentioning names of the perpetrator if it will stop them from following his ways or cause the perpetrator to repent and fix what he did out if pressure. But as soon as he repents you can’t tell anyone what he did in the past. Also you can’t tell anyone what happened until the victim is informed because if he finds out from someone else it might create more animosity towards the perpetrator then he would have if he was first told what and who did by the eyewitness who promises him he can try to get the situation resolved, or at least under control.