Sheikh `Atiyyah Saqr, former head of Al-Azhar Fatwa Committee, states: “It is mentioned in Al-Qurtubi’s Tafsir of the Qur’an that mosques should be protected from acts of buying and selling.
He cites a hadith reported by Muslim: “Mosques are built for a certain purpose (i.e., worship).”
Al-Qurtubi says that this is an indication that nothing should be practiced in mosques except prayers, recitation of the Qur’an and dhikr (remembrance of Allah), and this was supported by the hadith mentioned above.
At-Tirmidhi reported that the Prophet (peace and blessings be upon him) forbade people from reciting poetry or buying and selling things inside the mosque.
A group of scholars don’t approve of the act of buying and selling in the mosque. This is the opinion held by Imam Ahmad ibn Hanbal and Ishaq.
Al-Qurtubi adds that At-Tirmidhi said that some scholars of the Companions’ successors permitted buying and selling in the mosque. It is also reported in more than one hadith that the Prophet (peace and blessings be upon him) gave a concession to some people to recite poetry in the mosque.
The four main schools of fiqh (Islamic Jurisprudence) agree on that concluding any contract of give-and-take dealings, such as buying and selling, in the mosque is a blameworthy act (makruh), with the exception of those whose proceeds are for charity, for there is nothing wrong with them.
Both the Hanafi and the Maliki schools of fiqh agree on this, while the Hanbali school maintains that buying, selling, and hiring in the mosque is completely forbidden, so that if such a contract is concluded in the mosque, it will be regarded as invalid.
The Shafi`i school considers that such acts of buying and selling are not to be concluded in the mosque. However, if it happen as a rare event, it is not recommended. If it hinders people from performing prayer, it will be prohibited.
Thus, commercial dealings in the mosque are blameworthy, according to the majority of jurists, and prohibited and invalid according to the Hanbali jurists.
Both the Shafi`i and Hanbali jurists maintain that using the mosque as a place for buying and selling is prohibited and so is the case if it prevents someone from performing prayer.
Actually, I consider any act of buying, selling and the like in the mosque to be absolutely prohibited, be it permanent or temporary.”