The subject of ‘doing the Friday prayer and other prayers behind a Shafi’i imam, by a Hanafi person’, has been evaluated in different ways by Hanafi scholars. As understood from the narrations, this kind of topics didn’t pose a problem in the first periods of Islam. For example, Imam Abu Yusuf prayed behind Caliph Harun Rasheed (who has led the prayer without renewing ablution after he was cupped (Hajamat) and he had obtained fatwa from Imam Malik hereof) and he also didn’t repeat his prayer. (Ali ibn Muhammad ibn Ebi’l-Izz ad-Dimashqi, Sherhu’l-Aqideti’t-Tahaviyye, Beirut, 1408/1988, book: 2, page = 530)
However, the late Hanafi scholars have suggested certain conditions for the validity of a salat like this. In the book Fetaway-I Hindiyye the next phrase is mentioned:
“It’s absolutely valid (saheeh) to pray behind an imam of Shafi’i madhhab. However, a Shafi’i imam must avoid controversial issues, because it’s possible that a member of Hanafi madhhab may be praying behind him. For example: when blood starts flowing from his body he has to renew ablution, he shouldn’t return to much from the direction of Qiblah and he should beware of other controversial issues like this. “(Al-Fetawa al-Hindiyye, Daru Sadir, 1991, Beirut, book: 1, page = 84)
In short, according to the last period Hanafi sholars there are some criteria for praying behind a Shafi’i imam. The imam must make ablution like Hanafis and he must stay away from things which invalidate prayers or ablution according to Hanafis. If anyone from the congregation (jamaat) knows that the imam has did something that breaks the prayer or ablution, then his salat behind that imam would be invalid.
But these claims aren’t based on any Quranic verse or authentic Hadith. A Hanafi person can follow a Shafi’i Imam (or members of other madhhabs) in prayer and vice versa.
It’s not allowed to pray behind a person who has ‘definitely’ polytheism (shirk) in his religion. The principle for being an imam is to have the correct religion. Until it’s proven otherwise, one could pray behind an imam without looking at controversial Fiqh issues.