They are led in prayer by one whom they dislike to lead them because of his lack of religious commitment, but they are not able to dismiss him
Question

We are led in prayer by a man whom all the worshippers dislike, to the extent that someone swore that he would not enter the mosque so long as he is leading the worshippers in prayer, and most of the residents of the area no longer pray in the mosque because of him. Please note that this man has memorized only a very small amount of Quran and he does not know anything about the rulings on prayer, and it is known that he has a bad attitude and causes a great deal of annoyance to his neighbours. Please note that there is someone who is more qualified than him to lead the prayer, but this man always puts himself forward without anyone asking him to, and no one goes forward to lead the prayer except his relatives only, if one of them is visiting him. Should we pray behind him, or should we pray individually, or go to another mosque?
Praise be to Allah.If the people dislike this imam because of his lack of religious commitment, ignorance, wrongdoing and annoying his neighbours, then he should not lead them in prayer, and he should be dismissed and someone who is more qualified to lead the prayer than him should be appointed as imam.
At-Tirmidhi (360) narrated that Abu Umamah (may Allah be pleased with him) said: The Messenger of Allah (blessings and peace of Allah be upon him) said: “There are three whose prayer will not go beyond their ears: the runaway slave until he returns; a woman who goes to sleep when her husband is angry with her, and an imam who leads the people in prayer when they dislike him.” Classed as sound by al-Albani in Sahih at-Tirmidhi.
Al-Khattabi said: It seems that this warning is about a man who is not qualified to lead the prayer but he still imposes himself and becomes the imam by force, so people resent his being the imam; but if he deserves to lead the prayer, then the blame is on those who resent him, and not on him.
(End quote from `Awn al-Ma`bud, 2/213).
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) was asked about a man who led some people in prayer when most of them disliked him.
He replied: If they dislike this imam for a religious reason, such as if he tells lies, wrongs people, is ignorant, follows innovation and the like, and they like the other one because he is more religiously committed than him, such as if he is more honest, more knowledgeable, and more religious, then that imam whom they like must be appointed, not the imam whom they dislike to lead them in prayer.
(End quote from Majmu` al-Fatawa, 23/373)
If it is not possible to dismiss him and appoint the imam who is more qualified, then the worshippers should leave his mosque and go to another mosque where they like the imam and he is one of those who memorize the Book of Allah, follow the Sunnah and knows the rulings on prayer.
If this is not possible for some of them, then they should still pray behind this imam and put up with him, whilst striving to speak to him and advise him by all possible means, and they should not pray individually, or pray in their houses even in congregation, because praying in congregation in the mosque is obligatory. The Sahabah and Tabi`in used to pray behind unjust and oppressive rulers, and they did not stop praying behind them.
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) said:
If it is not possible to prevent the one who openly follows innovation and does immoral actions from leading the prayer, because removing him could lead to greater harm than leaving him as imam, then it is not permissible to do that. Rather people should pray behind him in the case of those prayers that cannot be offered except behind him, such as Jumu`ah and Eid prayer, and prayers in congregation, if there is no other imam.
For this reason the Sahabah used to pray Jumu`ah and prayers in congregation behind al-Hajjaj, al-Mukhtar ibn Abi `Ubayd ath-Thaqafi and others, because missing Jumu`ah and prayers in congregation has more harmful consequences  than praying behind an evil imam, especially if refusing to pray behind him will not deter him from his evil. In that case, you are giving up what serves a legitimate purpose without being able to ward off this evil. Hence those who refuse to pray Jumu`ah and prayers in congregation behind all oppressive rulers are regarded by the early generations (the salaf) and the leading scholars as people of innovation. But if it is possible to pray Jumu`ah and prayers in congregation behind a righteous imam, that is better than praying them behind an evildoer.
End quote from Majmu` al-Fatawa, 23/343-344.
And Allah knows best.