An imam leads the Muslims in prayer and they dislike him, and he knows that
It is makrooh for a man to lead people in prayer when most of them dislike him for a justifiable reason, such as if he is lacking in religious commitment, because the Prophet (peace and blessings of Allaah be upon him) said: “There are three whose prayers do not go any further than their ears: a runaway slave until he returns, a woman who spent the night with her husband being angry with her, and one who leads people in prayer when they dislike him.” Narrated and classed as hasan by al-Tirmidhi.
Shaykh al-Islam Ibn Taymiyah (may Allaah have mercy on him) said:
If they dislike this imam for a reason that has to do with his religious commitment, such as lying, wrongdoing, ignorance, bid’ah (innovation) and so on, and they like another because his religious commitment is better, such as if he is more honest, more knowledgeable or more religiously committed, then the imam whom they like should be appointed to lead them, and that imam whom they dislike should not lead them in prayer. The Prophet (peace and blessings of Allaah be upon him) said: “There are three whose prayers will not go any further than their ears: a man who leads people in prayer when they dislike him, a man who does not come to pray until the time for the prayer is over, and a man who enslaves a man who has been set free.”
And he said:
If there is some enmity between the imam and the members of the congregation such as enmity based on whims and desires or differences of opinion, he should not lead them in a congregational prayer, because it cannot be perfected unless there is harmony between them. Hence the Prophet (peace and blessings of Allaah be upon him) said: “Do not make your lines ragged lest that create disharmony among your hearts.” But if the imam is religiously committed and follows the Sunnah, and they dislike him because of that, then it is not makrooh for him to lead them in the prayer, rather they are to be blamed for disliking him. Whatever the case, there should be harmony between the imam and the people who follow him (in the prayer); they should cooperate in righteousness and piety and refrain from hatred that is based on whims and desires and devilish aims. The imam should pay attention to the rights of the people who pray behind him, and he should not be harsh with them; and the members of the congregation should pay attention to the rights of the imam, and respect him. In conclusion, each party should put up with some criticism from the other that may not befit religious commitment and chivalry, because man is bound to have some faults and shortcomings.
See al-Mulakhkhas al-Fiqhi, 1/155-156.