Al-Hasan reported in mursal form that God's Messenger said, “A time is coming when people will talk in their mosques about their worldly affairs, so do not sit with them, for God has nothing to do with them.”
Abu Huraira said that he heard God’s Messenger say, “If anyone comes to this mosque of mine, coming only for some good which he will learn or teach, he ranks a mujahid in God’s path; but if anyone comes for some other purpose, he ranks as a man who looks at another’s property.”
Ibn Majah and Baihaqi, in Shu'ab al-iman, transmitted it.
As-Sa'ib b. Yazid said that when he was sleeping in the mosque a man threw a pebble at him, and when he looked he saw that it was ‘Umar b. al-Khattab, who said, “Go and bring me these two men.” He brought them and ‘Umar asked them what tribe they belonged to, or what place they came from. On their replying that they belonged to at-Ta’if, he said, “If you had belonged to Medina I would have given you a beating for raising your voices in the mosque of God’s Messenger.
Abu Umama said that a Jewish doctor asked the Prophet what places were best, but he did not answer his question, saying, “I shall say nothing till Gabriel comes.” So he remained silent, and when Gabriel came he asked him, but he replied, “The one who is asked knows no more than the one who asks, but I shall ask my Lord.” Later Gabriel said, “Muhammad, I approached my Lord nearer than I have ever come before.” When Muhammad asked about that, he replied, “Between Him and me there were seventy thousand veils of light, and He said that the worst places were their markets and the best their mosques.”*
*The source of the tradition is not given in the text. The editor of the Damascus edition says it comes rightly from Ibn Hibban from Ibn ‘Umar.