All perfect praise be to Allah, the Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad, sallallaahu ʻalayhi wa sallam, is His slave and Messenger.
Whoever prays behind an imam and then sees that the imam makes significant mistakes in reciting the Faatihah that change the meaning of the verses, it is obligatory on him to stop following this imaam. Ar-Ramli wrote, “If the imaam makes mistakes in reciting the Faatihah that change the meaning, it is obligatory to stop following him in prayer, just as is the case if the imaam misses one of the obligatory acts of prayer.” [Nihaayat Al-Muhtaaj]
In this case, if the actions of the person who stopped following the imaam coincide with those of that imam, bowing and prostrating with him, but without intending to follow him, then his prayer is valid. The Hanbali scholar Ar-Ruhaybaani wrote about praying behind a dissolute imam, “If his actions coincide with those of the impious imaam without holding the intention of following him, he is not required to repeat the prayer, because he did not follow a dissolute imaam.”
Allah knows best.