Al-Nawawi (may Allaah have mercy on him) said in his commentary on Saheeh Muslim (Sharh Saheeh Muslim):
“But gheebah (speaking about a person in his absence) is permissible if it is for some legitimate (shar’i) purpose, which includes six reasons:
The first is complaining about unjust treatment: it is permissible for a person who has been mistreated to complain to the ruler or judge, or other people who have the authority or power to deal with the person who has mistreated him. He can say, So and so mistreated me, or, he did such and such to me.
The second is seeking help to change some evil action, and bring a sinner back to the right path: so he may say to the person who he hopes can help: So and so is doing such and such, so try to stop him, and so on.
The third is seeking a religious ruling or fatwa: whereby a person may say to the Mufti: So and so – or my father, or my brother, or my husband – has treated me unjustly by doing such and such; does he have the right to do that? How can I deal with this and protect myself from his mistreatment? etc. This is permissible in cases of need. It is preferable to say in the case of a man or a husband or a father or a son that someone did such and such [i.e., describe it indirectly], but naming names is permissible, because of the hadeeth of Hind who said (to the Prophet (peace and blessings of Allaah be upon him): Abu Sufyaan is a stingy man.
The fourth is warning the Muslims against some evil: this may take various forms, such as mentioning the faults of narrators, witnesses and authors. This is permissible by scholarly consensus. Indeed, it is obligatory, in order to protect the sharee’ah. It also includes describing faults when one is consulted [about a person, for a serious reason such as business, marriage, etc.], and speaking up if one sees someone buying faulty goods or a slave who steals or commits zinaa or drinks wine etc. – he should mention that to the would-be purchaser if he does not know about it. This is by way of sincere advice, not to cause harm or offence or corruption. Also, if you see a seeker of knowledge frequently visiting a person who is immoral or who follows innovations, and taking knowledge from him, and you fear that he may be harmed, you must advise him by explaining the situation to him, with the aim of offering sincere advice. If you see a person in a position of authority which he cannot discharge properly because he is not qualified for it or because he is corrupt, you should tell whoever has authority over him and explain what he is really like so that he will not be deceived by him and so that he will discipline him – this is not gheebah, and it is obligatory to put things right.
The fifth is if a person is openly committing immoral deeds or following bid’ah: such as drinking wine, confiscating people’s property unlawfully, collecting extortionate taxes, being in charge of illegal activities etc. It is permissible to speak of what he is doing openly, but it is not permissible to speak of other things except for another reason.
The sixth is for the purposes of identification: if a person is known by a nickname such as al-A’mash (rheumy-eyed), al-A’raj (lame), al-Azraq (blue), al-Qaseer (short), al-A’maa (blind), al-Aqta’ (missing a limb) etc., this is permissible for purposes of identification, but it is haraam to use such names for the purpose of belittling a person, and if it is possible to identify them by using other words, this is better. And Allaah knows best.”