As for His ﷺ statement,
Enjoining good is charity and forbidding evil is charity." (Muslim)
Indeed enjoying the good and forbidding the evil is from the best of charities (Sadaqaat). This is the reason why Allah favored this nation over other than it from the (nations), He ﷻ said,
كُنْتُمْ خَيْرَ أُمَّةٍ أُخْرِجَتْ لِلنَّاسِ تَأْمُرُونَ بِالْمَعْرُوفِ وَتَنْهَوْنَ عَنِ الْمُنْكَرِ وَتُؤْمِنُونَ بِاللَّهِ ۗ وَلَوْ آمَنَ أَهْلُ الْكِتَابِ لَكَانَ خَيْرًا لَهُمْ ۚ مِنْهُمُ الْمُؤْمِنُونَ وَأَكْثَرُهُمُ الْفَاسِقُونَ['Aali 'Imran:110]
You [true believers in Islâmic Monotheism, and real followers of Prophet Muhammad ﷺ and his Sunnah (legal ways, etc.)] are the best of peoples ever raised up for mankind; you enjoin Al-Ma'rûf (i.e. Islâmic Monotheism and all that Islâm has ordained) and forbid Al-Munkar (polytheism, disbelief and all that Islâm has forbidden." (Aali Imran 3:110)
There must be conditions for enjoying good and forbidding evil and they are as follows:
1)That the individual who is commanding the good and forbidding the evil must be knowledgable about the legislated ruling. If he is ignorant then it is not permissible for him to speak. (This is) because the commander of good and the forbidder of evil is commanding with what the people believe to be legislated by Allah. (Thus), it's not for him to speak about the legislation of Allah with that which he has no knowledge of. Allah has forbidden that by the text of the Qur'an (what means).
قُلْ إِنَّمَا حَرَّمَ رَبِّيَ الْفَوَاحِشَ مَا ظَهَرَ مِنْهَا وَمَا بَطَنَ وَالْإِثْمَ وَالْبَغْيَ بِغَيْرِ الْحَقِّ وَأَنْ تُشْرِكُوا بِاللَّهِ مَا لَمْ يُنَزِّلْ بِهِ سُلْطَانًا وَأَنْ تَقُولُوا عَلَى اللَّهِ مَا لَا تَعْلَمُونَ[Al-A'raaf:33]
Say (O Muhammad ﷺ): "(But) the things that my Lord has indeed forbidden are AlFawâhish (great evil sins, every kind of unlawful sexual intercourse, etc.) whether committed openly or secretly, sins (of all kinds), unrighteous oppression, joining partners (in worship) with Allâh for which He has given no authority, and saying things about Allâh of which you have no knowledge." (Al-A'raf: 33)
From the evil affairs, is that a person speaks about something, saying that it is good while he has no idea about it being good and/or he says something is evil whilst having no idea that it is evil.
2) That he is knowledgeable about the one (he is) addressing, that he indeed has abandoned an obligation or did something forbidden.
If he doesn't know, then it is not permissible for him to (command the good or forbid the evil), because in that case he would be doing something that he has no knowledge of, Allah says in the Qur'an (what means).
وَلَا تَقْفُ مَا لَيْسَ لَكَ بِهِ عِلْمٌ ۚ إِنَّ السَّمْعَ وَالْبَصَرَ وَالْفُؤَادَ كُلُّ أُولَٰئِكَ كَانَ عَنْهُ مَسْئُولًا[Al-'Isra':36]
And follow not (O man i.e., say not, or do not or witness not, etc.) that of which you have no knowledge (e.g. one's saying: "I have seen," while in fact he has not seen, or "I have heard," while he has not heard). Verily! The hearing, and the sight, and the heart, of each of those you will be questioned (by Allâh)." (Al-Isra: 36)
There are certain people who have jealousy (over their religion) and eagerness to enjoin the good and forbid the evil, being hasty and censuring without having the knowledge of the condition of the one being addressed. For example, he finds a person with a woman in the market place, so he speaks to him regarding this saying, "Why are you walking with this woman?" Whilst he is not aware that he is a Mahram (male relative who it is permissible for her to be around) to her. This is a great error. If you are in doubt, then ASK before you speak. As for (the case) that there is not any evidence that obligates you to doubt, then do not speak. How great are the number of men that accompany their wives to the market places. Look at the Prophet ﷺ and how he dealt with the people in this matter.
A man entered the Jum'ah prayer while the Prophet ﷺ was giving the sermon and (the man) sat down, He ﷺ said to him, "Did you pray?" He said "No," then the (Prophet ﷺ) said,
Get up and pray two light units of prayer." (Bukhari and Muslim)
He didn't say to him why did you sit? Because when a person enters the Masjid he is forbidden from sitting before he prays two units of prayer. Any time you enter the Masjid, be it in the morning or the night, after Asr, Maghrib or Fajr, do not sit until you have prayed two units of prayer. So this man came and sat down but there was a probability that he could have prayed two units of prayer before sitting whilst the Prophet ﷺ didn't see him; that is why he said to him, "Did you pray?" He replied, "No." So he ﷺ said, "Pray two light units of prayer." Here (in this case) he didn't command him to stand up and pray until he asked him, this here is wisdom!
3) The third condition of enjoining the good and forbidding the evil is that as a result of forbidding the evil a greater evil doesn't occur. If a greater evil takes place as a result of that (i.e. the forbidding the evil), then it is not permissible, from the aspect of REPELLING THE GREATER EVIL BY THE LESSER OF THEM. If we say for example that we find a person doing an evil (act) like smoking, if we forbid him from smoking he will go and drink alcohol; then in that case we do not forbid him when we know that he will venture in to that which is far greater, in that case we do not forbid him from smoking. Why!? Because smoking is a lot less (evil) then drinking alcohol, the proof for this affair is Allah says in the Qur'an (what means).
وَلَا تَسُبُّوا الَّذِينَ يَدْعُونَ مِنْ دُونِ اللَّهِ فَيَسُبُّوا اللَّهَ عَدْوًا بِغَيْرِ عِلْمٍ ۗ كَذَٰلِكَ زَيَّنَّا لِكُلِّ أُمَّةٍ عَمَلَهُمْ ثُمَّ إِلَىٰ رَبِّهِمْ مَرْجِعُهُمْ فَيُنَبِّئُهُمْ بِمَا كَانُوا يَعْمَلُونَ[Al-An'aam:108]
And insult not those whom they (disbelievers) worship besides Allâh, lest they insult Allâh wrongfully without knowledge. Thus We have made fairseeming to each people its own doings; then to their Lord is their return and He shall then inform them of all that they used to do." (Al-An'am: 108)
Cursing the gods of the pagans has a legislated benefit, however, if it results in (the pagans) then cursing Allah ﷻ -when he is deserving praise and glorification- it becomes forbidden to curse (the pagan gods), this is why the Prophet ﷺ said,
May the curse of Allah be upon the one who curses his own parents." (Muslim)
And he ﷺ said,
From the major sins is when one curses his own parents." The (companions) said, "O Messenger of Allah, is there a person who curse his own parents?" He ﷺ said, "Yes, he curse the father of a person so that person then curse his father and he curse the mother of a person and as a result he curses his mother." (Muslim)
In summary: It is obligatory that a greater evil does not result because of his forbidding of an evil (or) REPELLING THE GREATER EVIL BY THE LESSER OF THE TWO. Then it is also obligatory that the enjoiner of good and the forbidder of evil (must) intend to rectify the creation and not to gain victory over them. (This is), because there are people who enjoin good and forbid evil to exercise their authority to avenge themselves. This is a great deficiency, there can result from it much good from the aspect of warding off the evil and commanding the good but it still remains to be a great deficiency. So when you enjoin good and forbid evil, make your intention in your heart that you want the rectification of the creation, not that you want to hold sway over them or be victorious over them. (Check your intention) so that you are rewarded and Allah puts blessings in your commanding and your forbidding, and Allah's aid is sought.