If there is no mosque available to you except the one whose imam is unfit to lead the prayer, then you and the others who object to his practices may gather together and perform the prayer on your own, leaving that mosque. Either build another mosque or set aside a suitable place for prayer until Allah—exalted is He—provides a righteous imam. This ruling applies when you are unable to press for the dismissal of the present imam and his replacement by someone more deserving; but if you are able to bring about such a replacement, that becomes obligatory upon you. Allah knows best.
Prayer behind an Associationist
Question: In the village where we live there is a man who recites the Qur’an without tartil (measured recitation), without tajwid (correct articulation), and without understanding. He believes in graves and the dead, makes vows to them, and holds that they can benefit or harm. Is it permissible to pray behind this imam, and may he lead the funeral prayer if someone dies while he himself remains upon these practices? Please issue us a fatwa, and may you be rewarded.
Answer: Whoever believes that the dead can benefit or harm, makes vows to them, and seeks closeness to them is committing major associationism—may Allah protect us—for he is worshipping other than Allah. It is therefore impermissible to pray behind him, for he is not a Muslim as long as he persists in that condition. Your duty is to counsel him, explain that this is major associationism, and tell him that he must repent to Allah, affirm pure oneness, abandon the worship of the dead, and worship his Lord alone with no partner. If he repents and turns back to Allah, it becomes permissible to pray behind him; but while he remains as he is, he is not a Muslim, his own prayer is invalid, and it is impermissible to pray behind him.