بسم الله الرحمن الرحيم
If some member of the mosque runs madrasa in the vicinity of the mosque then it is mandatory on him that he pays its rent to the mosque. Also it is mandatory to spend the collection made for the mosque in the needs of the mosque.
مراعاة غرض الواقفين واجبة.
It is not lawful to use it for madrasa. If the madrasa needs funds, then separate collection should be made for it.
Allah knows Best!
Darul Uloom Deoband
This answer was collected from the official ifta website of Darul Uloom Deoband in India.