Shaykh al-Islām also said:
Section
As for praying behind people of deviant inclinations and religious innovations, or behind people of immoral conduct, there is well-known disagreement and further detail which this is not the place to discuss at length.
However, the most balanced view concerning such people is that it is not permissible to appoint one of them to lead the prayer when someone else can be appointed. Anyone who openly displays immoral conduct or religious innovations must be rebuked and forbidden to persist in them. The least degree of such rebuke is to shun him so that he gives up his immorality and innovation.
For this reason, the majority of leading scholars distinguished between someone who actively promotes his deviation and someone who does not. The former has made the wrongdoing public and thus deserves to be rebuked, unlike someone who remains silent: he is like a person who conceals his sin and is therefore not publicly rebuked. When a sin remains concealed, it harms only the person committing it; but when it is made public and goes unchallenged, it harms the community at large.
This is why the hypocrites’ outward professions were accepted and their inner secrets left to Allah Most High, unlike those who openly displayed disbelief.