Short answer
No. Zakat must be handed over into the ownership of an eligible person, so it cannot pay for building a masjid, its bills, staff or repairs. A madrasa may take zakat only to spend on its poor students as their own. The four schools agree; give the masjid your sadaqah instead.
Zakat requires tamlik, transferring ownership to an eligible recipient. Spending it on a masjid, a building, a well, a road or a burial is not valid zakat. Zakat given to a madrasa is valid when it reaches poor students as theirs, for example as stipends, meals or books given to them.
The four schools agree on this.
Explanation
The Quran lists the people who receive zakat (9:60): the poor, the needy, its collectors, those whose hearts are to be won, captives, debtors, those in the cause of Allah, and stranded travellers. It names people, not projects. The Hanafi school adds that zakat is only paid when it is handed over into a recipient's ownership. A building cannot own anything, so money spent on one is not zakat.
The four schools agree that zakat cannot be used for:
- Building, extending or repairing a masjid.
- Its electricity, rent or cleaning.
- Salaries of the imam or teachers, since these are wages for work.
- Wells, roads, hospitals or Quran printing as general projects.
- Shrouding and burying the dead.
A few modern writers have read "in the cause of Allah" broadly enough to cover all good projects. The four schools did not, and the Hanafi fatwa does not.
Madrasas are different because they serve students. A madrasa can collect zakat as the agent of its poor students and spend it on them as their own: boarding, meals, clothes, books, or fees paid with their permission. Before you give, ask the madrasa how it uses zakat and whether it keeps it apart from general funds.
Many masjids run a separate zakat fund for local families in need, which is fine. For the building itself, give sadaqah: it is one of the best forms of sadaqah jariyah.
The evidence
Quran, Surah At-Tawba 9:60
۞ إِنَّمَا ٱلصَّدَقَٰتُ لِلْفُقَرَآءِ وَٱلْمَسَٰكِينِ وَٱلْعَٰمِلِينَ عَلَيْهَا وَٱلْمُؤَلَّفَةِ قُلُوبُهُمْ وَفِى ٱلرِّقَابِ وَٱلْغَٰرِمِينَ وَفِى سَبِيلِ ٱللَّهِ وَٱبْنِ ٱلسَّبِيلِ ۖ فَرِيضَةًۭ مِّنَ ٱللَّهِ ۗ وَٱللَّهُ عَلِيمٌ حَكِيمٌۭ ﴿٦٠﴾
Zakah expenditures are only for the poor and for the needy and for those employed to collect [zakah] and for bringing hearts together [for Islam] and for freeing captives [or slaves] and for those in debt and for the cause of Allah and for the [stranded] traveler - an obligation [imposed] by Allah. And Allah is Knowing and Wise.
The recipients of zakat are named categories of people.
Sahih al-Bukhari 1395
Sahih... تؤخذ من أغنيائهم وترد على فقرائهم ...
"It is taken from their rich and given back to their poor."
Zakat is described as passing from the rich into the hands of the poor.
Where the ruling is recorded
- al-Hidaya, Kitab al-Zakat, chapter on those to whom zakat may and may not be paid. A mosque may not be built with zakat, nor the dead shrouded with it, because there is no transfer of ownership.
- al-Durr al-Mukhtar with Radd al-Muhtar, Kitab al-Zakat, chapter on the recipients of zakat. Tamlik as a condition of zakat.
- al-Mughni, Kitab al-Zakat, on spending zakat on mosques and bridges. The Hanbali agreement that this is not allowed.
This answer is pending review by the scholars on our team. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.