‘Amr b. Shu'aib on his father’s authority reported his grandfather as saying that God’s Messenger prohibited the recitation of poems in a mosque, buying and selling in it, and sitting in a circle in a mosque on Friday before the prayer.
Fatima daughter of al-Husain said on the authority of her grand-mother, Fatima the elder,* that when the Prophet entered the mosque he would pray for blessings and safety for himself and say, “My Lord, forgive me my sins, and open to me the gates of Thy mercy.” And when he went out he would pray for blessings and safety for himself and say, “My Lord, forgive me my sins, and open to me the gates of Thy abundance.”
*The daughter of the Prophet who married ‘Ali.
Tirmidhi, Ahmad and Ibn Majah transmitted it. In the version of the last two she said that when he entered the mosque, and also when he came out, he said, “In the name of God, and peace be upon God’s Messenger,” instead of “he would pray for blessings and safety for himself.” Tirmidhi said that its isnad is not connected, for Fatima daughter of al-Husain was not born in the lifetime of Fatima the elder.
Narrated Abu Huraira reported God’s Messenger as saying:
When you see anyone buying or selling in a mosque, say, “May God not make your trading profitable!” And when you see anyone calling out in it about something lost, say, “May God not restore it to you.”