Attitude towards sinners who commit sin openly
Question

                When the people see a sinner committing sin openly, some of them despise him and his sin, and others despise and denounce the sin, without despising the one who commits it. It is as if they are saying: He may be better than us before Allah, but he has committed this sin, and so on. What is the correct attitude?
Praise be to Allah.The Muslim should hate the sin, and hate the sinner’s committing of that sin. If he sees him committing a sin, he should denounce it, advise him, remind him of Allah, alarm him by reminding him of punishment that may come in this world or the Hereafter, pray for him, seek refuge with Allah from falling into the same sin, and not help the Shaytaan against his Muslim brother.
Al-Bukhaari (6777) narrated from Abu Hurayrah (may Allah be pleased with him): A man who had drunk alcohol was brought to the Prophet (blessings and peace of Allah be upon him), and he said: “Beat him.” Abu Hurayrah said: Some of us beat him with their hands, some beat him with their sandals, and some beat him with their garments. When they had finished, one of the people said: May Allah disgrace you. [The Prophet (blessings and peace of Allah be upon him)] said: “Do not say such things; do not help the Shaytaan against him.”
It was also narrated by Ahmad (7985) as follows: “Do not say such things; do not help the Shaytaan against him. Rather you should say: ‘May Allah have mercy on you.’” Its isnaad is saheeh according to the conditions of al-Bukhaari and Muslim.
It was also narrated by Abu Daawood (4478) and al-Bayhaqi (17495) as follows:
A man who had drunk alcohol was brought to the Prophet (blessings and peace of Allah be upon him) who instructed his Companions to beat him. Some of them beat him with their sandals, some with their hands and some with their garments. Then he said “Enough!” Then he instructed them to rebuke him and tell him how reprehensible his deed was, and they said: Do you not feel embarrassed before the Messenger of Allah (blessings and peace of Allah be upon him) to have done such a thing? Then he let him go, and when he turned to leave, the people began to pray against him and revile him, and one of them said: O Allah, put him to shame, O Allah, curse him. The Messenger of Allah (blessings and peace of Allah be upon him) said: “Do not say such things; rather say: O Allah, forgive him, O Allah, have mercy on him.”
This hadith was classed as hasan by al-Albaani in Saheeh Abi Dawood.
Al-Haafiz Ibn Hajar (may Allah have mercy on him) said:
“Do not help the Shaytaan against your brother”: the way in which they would be helping the Shaytaan is that by making the sin fair-seeming to him, the Shaytaan wants to bring shame and disgrace upon him, so if they pray for him to be put to shame, it is as if they are fulfilling the aim of the Shaytaan.
End quote from Fath al-Baari (12/67).
Al-Qaari (may Allah have mercy on him) said:
Al-Qaadi said: If the Most Gracious puts him to shame, the Shaytaan will have power him. Or, when he hears those words, he will despair of the mercy of Allah and will persist in sin. Or he may become angry and stubborn, which will make him persist in sin, so this supplication against him will become a cause of his persisting in his evil deeds.
End quote from Mirqaat al-Mafaateeh (6/2374).
Abu Daawood narrated in az-Zuhd (232) from Abu Qilaabah that he said: A man was taken past Abu’d-Dardaa’ for a hadd punishment that he had incurred, and the people hurled insults at him. He said: Do not revile your brother, and praise Allah Who has protected you from sin. He said: Don’t you think that if you saw him in a dry well, you would rescue him and bring him out? They said: Yes. He said: So do not revile your brother, and praise Allah who has protected you from sin. It was said to him: Don’t you hate him? He said: I do not hate him; rather I hate his action, and if he gives it up, he will be my brother.
To sum up:
The Muslim should sincerely advise his Muslim brother and love good for him. If he falls into sin, he should not help the Shaytaan against him, or pray against him, or despise him; rather he should advise him sincerely, rebuke him and hate his action; he should ask Allah to protect him, and pray that He conceal his companion’s faults, enable him to repent, and forgive him.
But if this sinner commits a sin openly and blatantly, then this is blameworthy and reprehensible; and he should be hated for the sake of Allah commensurate with his sin. All possible measures should be taken to stop him and protect the people from his evil, even if that is by means of shunning him, because he is persisting in sin and boasting about it, and people are no longer safe from his evil.
It was narrated that Abu Hurayrah said: I heard the Messenger of Allah (blessings and peace of Allah be upon him) say: “All of my ummah will be fine except those who commit sin openly, and it is part of committing sin openly for a man to do something at night, then in the morning when his Lord has concealed him he says: O So and so, I did such and such last night, when his Lord had concealed him all night, but in the morning he discloses that which Allah had concealed for him.” Narrated by al-Bukhaari (5721) and Muslim (2990).
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) said:
If a man commits evil deeds openly, then he must be denounced openly, and speaking ill of him will not be regarded as gheebah (backbiting).  He should be punished openly with a punishment that will deter him, such as shunning and other punishments. He may not be greeted with salaam and his greeting may not be returned, provided that the one who does that is able to do it without it causing certain trouble. Good people and religiously-committed people should shun him after he dies, by not attending his funeral, as they shunned him when he was alive, if that could serve the purpose of deterring other sinners of his ilk.
End quote from Majmoo‘ al-Fataawa (28/217).
Al-Haafiz Ibn Hajar (may Allah have mercy on him) said:
Whoever commits sin openly and blatantly has angered his Lord and He will not conceal him.
Whoever conceals his sin out of shyness before his Lord and before the people, Allah will bless him by concealing his sin.
End quote from Fath al-Baari (10/488).
So there is a differentiation between the one who is overcome by his nafs [lower self] and follows his whims and desires, and thus disobeys Allah, but he does not commit his sin openly or persist in it, so his shortcoming should be concealed, and he should be advised and reminded of Allah, and we should pray that he be guided, and he should not be despised or humiliated, and he should be called to repent, then if he repents, perhaps after he repents he may be better off than he was before he committed the sin;
and this is in contrast to the one who blatantly, stubbornly and defiantly commits sin openly and boasts about it; he should be denounced and advised, and we should pray that he be guided too. Then if he persists and does not stop, he should be punished and spoken ill of among people, and they should shun him and shame him, and warn people against him.
It cannot be said of such a person that perhaps he is better before Allah than us, because his state is the worst of states, for he is exposed to the wrath and anger of Allah, and His imminent punishment.
We ask Allah to turn to us and to every Muslim in mercy.
And Allah knows best.