Reference: Fataawa Islaamiyyah – Volume 1, Page 383
Question: I entered the masjid to pray, but I found an imaam whom I do not like to pray behind; what should I do so that I gain the reward for the congregational prayer?
Response: If you entered the masjid to offer the congregational prayer and you found them praying, then pray with them, even if the imaam is a person whom you dislike, because the congregational prayer is obligatory and in such case you are bound by that duty.
And there remains the question of why you dislike this man? Is it due to some defect in his religion, or personal enmity between you?
If it is due to personal enmity, then it is incumbent upon the Muslim to remove whatever rancour exists between him and his brother and replace it with harmony and brotherly love, as Allaah (Subhaanahu wa Ta’aala) says:
{The believers are but brothers}, [Soorah al-Hujuraat, Aayah 10]
However, if your dislike of him is due to some defect in his religion, then it is incumbent upon you to advise him and make clear to him what is wrong in his religion, so that he may correct it and to go straight upon the path which Allaah has ordained. As for people renouncing each other whenever they see some defect in each other’s religion, and contenting themselves with concealing their rancour and enmity for each other, this conflicts with the state of the believers about whom Allaah says:
{You are the best of people ever raised up for mankind; you enjoin al-Ma’roof (all that Allaah has ordained) and forbid al-Munkar (all that Islaam has forbidden) and you believe in Allaah}, [Soorah Aal ‘Imraan, Aayah 110]