If this woman is one of his mahrams, there is nothing wrong with him leading her in prayer and it will be counted as prayer in congregation. But if she is a non-mahram, and if his leading her in prayer means that he will be alone with her, then in this case his leading her in prayer is haraam.
It says in al-Muhadhdhab: It is makrooh for a man to lead a non-mahram woman in prayer, because it was narrated that the Prophet (peace and blessings of Allaah be upon him) said: No man is alone with a non-mahram woman but the Shaytaan is the third one present.
Al-Nawawi said in his commentary:
What is meant by it being makrooh is that it is haraam. This applies if he is alone with her.
Our companions said: If a man leads his wife or a woman who is his mahram in prayer, and is alone with her, that is permissible and is not makrooh, because it is permissible for him to be alone with her in situations other than prayer. If he leads a non-mahram woman in prayer and is alone with her, that is haraam for him and for her, because of the saheeh ahaadeeth that I will quote below, in sha Allaah.
If he leads (a number of) non-mahram woman in prayer and is alone with them, the majority of scholars said that this is permissible, and this was narrated by al-Raafa'i in Kitaab al-Adad from our companions.
His evidence is the hadeeth which we will quote below, in sha Allah, and because when there are a number of women together, a man cannot usually behave inappropriately one of them in the presence of the others.
With regard to the ahaadeeth mentioned above, one of them is the report narrated from Uqbah ibn Aamir (may Allaah be pleased with him), that the Messenger of Allaah (peace and blessings of Allaah be upon him) said: Beware of entering upon women. A man from among the Ansaar said: O Messenger of Allaah, what do you think about the in-law? He said: The in-law is death. Narrated by al-Bukhaari and Muslim. The in-law refers to the husband's relatives; what is meant here is a relative who is not her mahram, such as the husband's brother, paternal uncle, cousin, maternal uncle, etc. The husband's father, son and grandfather are mahrams and it is permissible for them to be alone with his wife, even though they are also in-laws.
It was narrated from Ibn Abbaas (may Allaah be pleased with him) that the Messenger of Allaah (peace and blessings of Allaah be upon him) said: No one of you should be alone with a woman unless a mahram is present. Narrated by al-Bukhaari and Muslim.
It was narrated from Ibn Amr ibn al-Aas (may Allaah be pleased with him) that the Messenger of Allaah (peace and blessings of Allaah be upon him) said from the pulpit: After this day, no man should enter in secret upon a woman whose husband is absent unless there is another man or two with him. Narrated by Muslim.
What is meant by a woman whose husband is absent means one whose husband is not in the house, even if he is in the same town. Al-Majmoo', 4/173, 174.
Shaykh Ibn Uthaymeen (may Allaah have mercy on him) said:
The phrase leading a non-mahram woman or women in prayer who have no man with them means: it is makrooh to lead a non-mahram woman or women in prayer.
What the author says requires further explanation:
If there is one non-mahram woman on her own, then to say that it is only makrooh requires further explanation, if that means being alone with her. Hence it was interpreted in al-Rawd as meaning that the Prophet (peace and blessings of Allaah be upon him) forbade a man to be alone with a non-mahram woman. But we say: If he is alone with her then it is haraam for him to lead her in prayer, because that which may lead to something haraam is also haraam.
If there is more than one woman, i.e., if he leads two women in prayer, this is also subject to further discussion as to whether it is makrooh, because if there is a second woman along with the first, this means that khulwah (being alone with a non-mahram member of the opposite sex) is no longer an issue, and if the man is trustworthy there is nothing wrong with him leading the two women in prayer. This happens sometimes in some mosques where the congregation is small, especially with regard to qiyaam al-layl in Ramadaan, when a man comes to the mosque and finds no men there, but he does find two or three or four women in the back of the mosque. According to what this author is saying, it is makrooh for him to lead these two or three or four women in prayer.
But the correct view is that this is not makrooh, and that if he leads two or more women in prayer, there is no khulwah and it is not makrooh, unless he is afraid of fitnah (temptation). If he is afraid of fitnah, then it is haraam, because whatever is a means that may lead to something haraam is also haraam.
From the phrase if there is no man with them we may understand that if there is a man with them, then it is not makrooh, this is clear.
Al-Sharh al-Mumti', 4/250-252.
And Allaah knows best.
Reproduced from Islam QA