Actually the Gemara in Moed Qattan is quite clear about what it means. It comes in the context of story about a rabbi who was excommunicated by Rabbi Yehudah for sinful private behaviour. On his death bed, R. Yehudah was proud of the fact that he stood up to such a prominent rabbi. After the sinful rabbi died, they tried to bury him with the "Chasidim" but his body was miraculously rejected.
Rabbinic leaders must be beyond reproach in their personal conduct, especially with regard to sexual matters. A person who does not reach these standards, must be removed from their position (and excommunicated!) regardless of the vital work they are doing with their community. Even after their death, they are not to be remembered as "Chasidim" (tzadikim).
This is a critical lesson that has never been more timely. A few years back I had some conversations with leading figures in the American Modern Orthodox community urging that their organisation cease from referring to a recently departed leading posek as zt"l and publicly celebrating his tzidkus due to his activities protecting child abusers and intimidating those who report them. I quoted them this gemara. The message does not seem to have gotten through.