It is permissible to follow the Imam 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 Imam, as they are all with in the area of the mosque, then it is permissible to do so and the prayer is valid.
Sheikh Muhammad Saleh Al-Munajjid, a prominent Saudi Muslim scholar and lecturer, states: “It was narrated that Zayd ibn Thabit (may Allah be pleased with him) said: The Messenger of Allah (peace and blessings 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 hadith in which this incident is described, it says: “The best prayer a man prays is that offered in his house, except for the obligatory prayers.” (Agreed upon). This hadith indicates that it is permissible to follow the Imam 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 they should be able to follow the Imam within the area of the same mosque. If this is possible, there is no dispute among the scholars that it is permissible to do so.
The hadeeth also indicates that the presence of a barrier between the Imam and the members of the congregation does not mean that the prayer and their following the Imam are rendered invalid. An-Nawawi said: “For their following to be valid, the person following has to know when the Imam 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 Imam or other members of the congregation, even if the rows are interrupted, the prayer is still valid. This is because there is nothing to make it invalid and there is something to make it valid, which is that he can see either the Imam or some of the people behind him, and he is able to follow the prayer.
In Al-Insaf we read: “With regard to the continuity of the rows, reference should be made to `urf (local custom, i.e., what is traditionally regarded as being complete), and this is the correct view. Also, in Al-Mughni it says: “Interruptions (in the rows) do not matter. This is the view of Malik and Ash-Shafi`i. There is no limit to the rows because it does not prevent one from following the Imam. What matters is that which would prevent a person from seeing or hearing the Imam. An-Nawawi made it a condition that there should not be big gaps outside the mosque, and this is the view of the majority of scholars.”
Sheikh Tayes Al-Jumaily, a Qatari Muslim Jurist and scholar of Iraqi origin, states that: “If the people following the Imam are in a level (another floor) that does not affect their ability to follow the Imam, then the prayer is still valid. The prayer will be valid as long as they are able to follow the Imam though hearing his voice through the speakers.”