Ruling on praying with these people
We ask Allaah to set the affairs of your village, and of all the Muslims, straight, and to guide its people to the right way, and to rid them of fitnah and the traps of the Shaytaan, and to send you a righteous imam who will establish prayer among you as commanded by Allaah and guide you to the path of your Lord by his words and deeds.
People like this imam should not be appointed to this important religious position, that of leading the people in prayer. Rather he should be denounced and rebuked for his evil actions, and ostracized if that will put an end to his evildoing and wrongful actions. As for not praying behind him, it is not permissible to stop praying behind him, unless there is another imam who is better than him in religious commitment and who does not commit wrongdoing or follow his whims and desires.
Similarly with regard to those inhabitants of your village who pray behind him, you have to pray with them even if there are evildoers and wrongdoers among them.
Shaykh al-Islam Ibn Taymiyah (may Allaah have mercy on him) said:
If a member of the congregation knows that the imam is an innovator who calls others to follow his innovation (bid’ah), or is an evildoer who commits evil openly, and he is the regular imam and he has no choice but to pray behind him, such as the imam for Friday prayers and Eid prayers, or the imam who leads the prayers during Hajj in ‘Arafah, and the like, then he must pray behind him, according to most of the earlier and later scholars. This is the view of Ahmad, al-Shaafa’i, Abu Haneefah and others.
Hence they said in al-‘Aqaa’id: he should offer Friday prayers and Eid prayers behind any imam, whether he is righteous or immoral.
Similarly, if there is only one imam in the village, then all people should pray behind him, because praying in congregation is better than a man praying alone, even if the imam is an evildoer. This is the view of most the scholars: Ahmad ibn Hanbal, al-Shaafa’i and others. Indeed, praying in congregation is an individual obligation according to the well-known view of Ahmad.
Whoever does not pray Jumu’ah or pray in congregation behind an immoral imam is an innovator according to Imam Ahmad and other Sunni imams.
The correct view is that he should offer the prayers and not repeat them, because the Sahaabah used to pray Jumu’ah and prayers in congregation behind immoral imams and they did not repeat the prayers. Ibn ‘Umar used to pray behind al-Hajjaaj, and Ibn Mas’ood and others used to pray behind al-Waleed ibn ‘Uqbah, who was a wine-drinker. One day he led them in prying Fajr and made it four rak’ahs, then he said: “Shall I increase it for you?” and Ibn Mas’ood said: “Things are getting worse.” Hence they complained about him to ‘Uthmaan…
The prayer of an evildoer or an innovator is itself valid, so if someone prays behind them his prayer does not become invalid. But some scholars regarded praying behind them as makrooh because it is obligatory to enjoin what is good and forbid what is evil, and part of that (i.e., part of enjoining what is good and forbidding what is evil) is that one who commits innovation or evil openly should not be appointed to lead the Muslims, because he deserves to be punished or rebuked until he repents. If it is possible to ostracize him until he repents, that is good. If the fact that some people leave him and pray behind someone else will have the effect of making him repent or causing his dismissal, or will deter others from committing sins like him, in that case, if they refrain from praying behind him, that will serve an interest and the member of the congregation will not miss Jumu’ah prayers or prayers in congregation. Otherwise, if not praying behind him will make the member of the congregation miss Jumu’ah prayers or prayer in congregation, in that case the one who stops praying behind him is an innovator who is going against the Sahaabah (may Allaah be pleased with them).
Similarly, if the imam has been appointed by the authorities, and stopping praying behind him will not serve any purpose, then he should not stop praying behind him, but praying behind the better imam is better. See Majmoo’ al-Fataawa, 23/352.
Imam al-Tahhaawi (may Allaah have mercy on him) said in his ‘Aqeedah, in which he mentioned several basic principles of Ahl al-Sunnah:
We believe that we may pray behind any Muslim who turns towards the qiblah in his prayers, righteous or immoral, and we offer the funeral prayer for any Muslim who dies.
Along the same lines, Abu Dawood (594) narrated that Abu Hurayrah (may Allaah be pleased with him) said: The Messenger of Allaah (peace and blessings of Allaah be upon him) said: “The prescribed prayer is obligatory and should be offered behind any Muslim, whether he is righteous or immoral, even if he commits major sins.”
(Classed as weak by al-Albaani in Da’eef Abi Dawood)
Even though this hadeeth does not have any sound isnaad, as was quoted in ‘Awn al-Ma’bood from al-‘Aqeeli and al-Haafiz ibn Hajar, al-Shawkaani (may Allaah have mercy on him) said: But it is proven that there was consensus among the people of the first era, the remaining Sahaabah and the Taabi’een who were with them, based on their actions, and it is not farfetched to say that it was also based on their statments, that they prayed behind unjust rulers, for the rulers at that time also led the five daily prayers, and the people were not led in their prayers by anyone other than their governors in every town that had a governor.
In his Saheeh, Imam al-Bukhaari entitled one of his chapters Baab imaamat al-Maftoon wa’l-Mubtadi’ (Chapter on immoral people and innovators leading the prayer), then he narrated (695) from ‘Ubayd-Allaah ibn ‘Adiyy ibn Khiyaar that he entered upon ‘Uthmaan ibn ‘Affaan (may Allaah be pleased with him) when he was under siege and said: “You are the imam of the people and there has befallen you what we see, and now the imam of fitnah leads us in prayer and we are afraid of committing sin.” He said: “Prayer is the best deed that people can do. If the people do good then do good with them, but if they do evil, then avoid their evil.”
Al-Haafiz ibn Hajar (may Allaah have mercy on him) said: “The apparent meaning is that he allowed him to pray with them, as if he said: It doesn’t matter that he is an evildoer, rather if he does good then join him in doing good, but avoid him with regard to his evil.
It was narrated from Sahl ibn Yoosuf al-Ansaari that his father aid: The people did not like to pray behind those who had besieged ‘Uthmaan, but ‘Uthmaan said: “Whoever gives the call to prayer, answer him.”
This clearly points to what he meant when he said, “Prayer is better.” This indicates that he gave permission to pray behind him and this supports the author’s view.
Al-Haafiz said: These reports indicate that we are encouraged to attend prayers in congregation, especially at times of fitnah (tribulation), otherwise the division will spread even further.
It also indicates that praying behind someone whom one does not like to pray behind is better than abandoning prayer in congregation.
In conclusion: It is not permissible for you to stop praying with the people of your village and pray alone in your house or elsewhere. Rather what you have to do is to pray in congregation with the people. If you can find an imam who is just and righteous, then pray with him, otherwise pray with the imam you mentioned, and you will have the reward for praying in congregation with him, and he will bear the burden of his wrongdoing and evil actions.
And Allaah is the Source of strength.