All perfect praise be to Allah, The Lord of The Worlds; and may His blessings and peace be upon our Prophet Mohammad and upon all his family and companions.
In principle, Muslim jurists hold the view that it is impermissible to transfer an endowment to a party or to spend its benefit in a channel other than that to which it has been endowed in the first place
. A mosque is a place of prayer, supplication, I`tikaf (seclusion in the mosque for worship), teaching the Quran, and observing all acts that make a person nearer to Allah, The Almighty. Therefore, using an area of the mosque for observing the aforementioned acts doesn`t affect the function of the mosque, which is the party and the channel to which the endowment has been endowed in the first place. The book, “Rawdat At-Talibeen” states: “It isn`t discouraged to stay in the mosque for teaching the Quran, teaching religious sciences, and delivering Fatwas.”
Consequently, there is no objection in Sharia as regards using the upper floor of the mosque for teaching the Quran, so long as the Sharia rules pertaining to the mosque are observed. This floor, with having its own rules, should remain part of the mosque, and so it is impermissible to stop people from praying in it when the mosque gets crowded. It is also impermissible for a woman in menses, or a ritually impure person to stay in it. Moreover, it is impermissible to have water closets in it, or to make any changes that hinder people from observing prayer in any part of that floor. And Allah knows best.