Praise be to Allah.
The majority of fuqaha’ are of the view that it is makrooh to plant trees in the mosque, and some of them are of the view that it is haraam, and some of them limited the prohibition to those that take up space that should be for the worshippers.
The reason why it is makrooh is that the mosque was not built for that purpose, rather it was built for the remembrance of Allaah, prayer and reading Qur'aan, and because the tree may damage the mosque and prevent worshippers from praying in the spot where it is located, and its leaves and fruits will fall in the mosque, and birds will come to it and defecate in the mosque, and children may come to the mosque because of the tree and throw stones at it to make its fruits fall.
Some of them gave the reason for it being makrooh as being because it is making the mosque similar to the synagogues of the Jews.
Ibn Qudaamah (may Allaah have mercy on him) said: It is not permissible to plant a tree in the mosque. This was stated by Ahmad, who said: If the date palm was planted after it became a mosque, then this was planted unlawfully, and I would not like to eat from it. If the imam uproots it, that is permissible, because the mosque was not built for that purpose, rather it was built for the remembrance of Allaah, prayer and reading Qur'aan, and because the tree may damage the mosque and prevent worshippers from praying in the spot where it is located, and its leaves and fruits will fall in the mosque, and birds will come to it and defecate in the mosque, and children may come to the mosque because of the tree and throw stones at it to make its fruits fall.. End quote from al-Mughni (5/370).
In al-Fataawa al-Hindyyah (1/110) it says: It is makrooh to plant trees in the mosque, because that is making it like a synagogue, and because it takes space away from the worshippers , unless it will be of benefit to the mosque, such as if the land is wet and unstable and the pillars would not be steady, so trees are planted therein to reduce the instability. This is what it says in the Fataawa of Waadi Khaan. End quote.
Ibn al-Humaam (may Allaah have mercy on him) said: It is not permissible to plant trees in it unless the land is wet and unstable and the pillars are not steady, in which case it is permissible in order to absorb that water and bring about some benefit. End quote from Fath al-Qadeer (1/421).
Zakariya al-Ansaari (may Allaah have mercy on him) said: And it is makrooh (to dig a well or plant trees in it), rather if that causes harm it is haraam (and the imam may remove it) lest it take space away from the worshippers. Al-Adhra’i said that planting trees in a mosque that is structurally sound is haraam because it takes space away from the worshippers, and causes problems, and brings impurities from bird lime. And he narrated from a number of the Iraqis that planting anything is not allowed. End quote from Asna al-Mataalib (1/186).
In Sharh al-Kharashi ‘ala Khaleel (7/48) it says: Note: a number of scholars clearly stated that it is not allowed to plant anything in the mosque. They said it is not permissible to dig therein or to bury anyone therein. They said: Perhaps those who said it is makrooh meant that it is makrooh in the sense of being haraam. End quote.
Thus it is clear that the fuqaha’ said it is either haraam or makrooh. This applies to things that are planted in the mosque after it is built. But if there were any plants on the land before the mosque was built, and the mosque is built around it, there is nothing wrong with that.
Ibn Qudaamah said, in the passage quoted above: If there was a date palm on the land, and its owner made it into a mosque and the date palm is incorporated into it, there is nothing wrong with that. End quote.
It also seems that there is nothing wrong with there being trees in a garden attached to the mosque, so long as they do not take away any space from the worshippers and their leaves do not cause any problem for the mosque.
With regard to eating the fruits of these trees, that is subject to further discussion. If the one who set up the waqf donated the trees along with the mosque and specified on what the waqf was to be spent, by stating that it is for the poor, or for imams or students or the mosque, for example, then his request is to be followed. What has been donated as a waqf to the mosque should be sold and spent on the mosque.
2 – If he did not specify how the waqf was to be spent, then there is a difference of scholarly opinion concerning that. It was said that the ruling is the same as that for which the beneficiaries are not stipulated, so it should be given to the heirs of the original donor as a waqf for them, or it was said that it is permissible for the poor of the mosque, or that it may be spent on the mosque.
3 – In the case of that which is planted in the mosque but was not given as a waqf along with it, and which we have ruled to be makrooh or haraam, if it was planted for the mosque then nothing should be taken from it without paying something to the mosque in return. If it was planted for the sake of Allaah or it is not known for what purpose it was planted, it is permissible to eat from it, but it is better not to eat from it, but if a person eats from it and donates something for the upkeep of the mosque in return, there is no sin on him.
There follow some comments of the fuqaha’ on this issue:
Ibn Qudaamah said in the same place as quoted above: If its owner says: This is a waqf for the mosque, then its fruits should be sold and the price donated to the mosque.
Al-Safareeni (may Allaah have mercy on him) said: Question: Ruling on eating the fruits of trees belonging to the mosque. In al-Furoo’, al-Insaaf, al-Iqnaa’, al-Muntaha, al-Ghaayah and elsewhere, it says that if they are not removed, then their fruits are for the poor of the mosque. It says in al-Insaaf: al-Haarithi said: This is our view. He said: It is more likely that they are permissible for other poor people too. Imam Ahmad (may Allaah have mercy on him) said: I would not like to eat from them.
If it was planted before the mosque was built and was given as a waqf along with it, then if (the donor) specified how (the fruits) were to be disposed of, his wishes should be followed, otherwise it should be given to the heirs of the donor, both rich and poor, as a waqf to them according to their shares of inheritance. They are entitled to it as an inheritance. If he has no relatives then it is for the poor and needy as a waqf for them. al-Muwaffaq said: It is permissible to eat from it, and this is the view of Imam Ahmad according to the report narrated by Abu Taalib. ... A number of our companions said: It should be (sold and the money) spent on the mosque, and if there is no need of it then its neighbour may eat the fruits. He stated this in al-Faa’iq. But he stated the former view, that if no particular recipient is stipulated then it is like a waqf for which no recipient were stipulated, in al-Iqnaa’, al-Muntaha and al-Ghaayah. (2/317).
In Haashiyat al-Bujayrimi (3/103) it says: It is makrooh to plant trees in the mosque as it says in al-Rawdah. I say: This is to be understood as meaning that it is makrooh if it does not affect the mosque or the worshippers, otherwise it is haraam and if it has been planted it should be uprooted. The one who should uproot it is the imam or his deputy, not individuals, whether it was haraam or makrooh to plant it, because he has the right to remove makrooh things. But it is not permissible to cut down that which was planted for the mosque and is not causing any harm, because it belongs to the mosque. This was stated by al-Qaadi. But it should be limited to that which bears fruits from which the mosque may benefit, otherwise it should be removed. The basic principle dictates that attention should be paid to whichever serves the greater interest: leaving it or removing it.
In the case of things that were planted for the mosque but deserve to be removed, it is not permissible to eat their fruits unless one makes a donation to the mosque in return. If they were planted to provide food for the sake of Allaah or the intention of the one who planted them is unknown, it is permissible to eat from them without paying anything in return. The same applies to the fruits of trees planted for the sake of Allaah in the graveyard or if the intention of the one who planted it is not known, and the same applies to plants that grew there by themselves. End quote.
Ibn Qudaamah said: Abu’l-Khattaab said: In my view, if the mosque needs the price of the fruits of the trees, they may be sold and the price given towards upkeep of the mosque. He said: Ahmad’s view is that the neighbours may eat them, which may be understood as meaning that they attend the mosque and take care of it. End quote.
Based on this, if the fruits of the garden asked about here were donated as a waqf for a specific cause, then it is not permissible for anyone but the specified recipients to eat from them.
If they were planted for the sake of Allaah, it is permissible to eat from them without paying anything in return.
If they were given as a waqf or planted for the benefit of the mosque, then they should be sold and the money spent on the mosque. If a person takes some of them and puts some money in the mosque collection box in return, then he has done the right thing.
And Allaah knows best.