Praise be to Allah.
It was narrated that Zayd ibn Thaabit (may Allaah be pleased with him) said: The Messenger of Allaah (peace and blessings of Allaah be upon him) was staying in a hut made of palm leaves. He prayed in that hut and some men followed him, they came and prayed with him. And in the hadeeth in which this incident is described, it says: “The best prayer of a man is prayers offered in his house, except for the obligatory prayers.” (Agreed upon)
This hadeeth indicates that it is permissible to follow the imaam even if he is in a room where the person following him cannot see him, or if one of them is on the roof and the other is in a lower place. The point is that if it is possible to follow the imaam if they are all inside the mosque, there is no dispute among the scholars that it is permissible for him to do so.
The hadeeth also indicates that the presence of a barrier between the imaam and the members of the congregation does not mean that the prayer and their following the imaam are invalid. Al-Nawawi said: “For their following to be valid, the person following has to know when the imaam moves, whether they are praying in the mosque or elsewhere, or one of them is in the mosque and the other is outside – this is according to scholarly consensus.”
If one of them is outside the mosque and he can see the imaam or other members of the congregation, even if the rows are interrupted, the prayer is valid because there is nothing to make it invalid and there is something to make it valid – which is that he can see either the imaam or some of the people behind him, and he is able to follow the prayer.
In al-Insaaf it says: with regard to the continuity of the rows, reference should be made to al-‘urf (local custom, i.e., what is traditionally regarded as being complete), according to the correct view.
It says in al-Mughni: interruptions (in the rows) do not matter. This is the view of Maalik and al-Shaafa'i, because there is no limit in that, since it does not prevent following the imaam. What matters here is what would prevent a person from seeing or hearing the imaam. Al-Nawawi made it a condition that there should not be big gaps outside the mosque, which is the view of the majority of scholars. And Allaah knows best.