If the donors who contributed to the solar power system explicitly stated that the funds were solely for installing a solar power system in the mosque, then using its electricity for facilities connected to the mosque (such as the Imam's residence) would not be permissible. However, if they have explicitly given permission for this, or at least implicitly indicated their approval—meaning it is unlikely they would object if they discovered that the Imam’s residence was also being powered by the mosque’s solar power system—then it would be permissible for the Imam and his family to use the mosque’s solar power system for their necessary needs. Even then, they must be extremely careful when using electricity to avoid any waste.
As for the neighbours, it is not permissible for them to use the electricity generated by the mosque’s solar power system. However, if the donors who contributed to the installation of the system have explicitly given permission for the neighboring residents to use it, then they would be allowed to use only as much electricity as strictly needed, provided that they do not cause any harm to the mosque while doing so.
۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔
دلائل:
البحر الرائق: (232/5، ط: دار الكتاب الإسلامي)
"أي مصالح المسجد، فیدخل المؤذن والناظر؛ لأنا قدمنا أنهم من المصالح، وقدمنا أن الخطیب داخل تحت الإمام لأنہ إمام الجامع، فتحصل أن الشعائر التي تقدم في الصرف مطلقًا بعد العمارۃ الإمام والخطیب والمدرس والوقاد والفراش والمؤذن والناظر وثمن القنادیل والزیت والحصر.
الهندية: (462/2، ط: دار الفكر)
متولي المسجد ليس له أن يحمل سراج المسجد إلى بيته وله أن يحمله من البيت إلى المسجد، كذا في فتاوى قاضي خان.
Allah the Almighty knows best.
Darul ifta Al-Ikhlas, Karachi.