Sahih Muslim Book 6 – Hadith 82-89
Chapter 10: What to say when entering the masjid.
Abu Usaid reported that the Messenger of Allah (ﷺ) said:
When any one of you enters the mosque, he should say:" O Allah! open for me the doors of Thy mercy"; and when he steps out he should say: 'O Allah! I beg of Thee Thy Grace." (Imam Muslim said: I heard Yahya saying: I transcribed this hadith from the compilation of Sulaiman b. Bilal.) (Sahih Muslim Book 6 – Hadith 82)
A hadith like this has been narrated from the Messenger of Allah (ﷺ) by Abu Usaid. (Sahih Muslim Book 6 – Hadith 83)
Chapter 11: It is recommended to greet the masjid by praying two rak`ah, and it is disliked to sit before praying these two rak`ah, and this is prescribed at all times.
Abu Qatada (a Companion of the Prophet) reported Allah's Messenger (ﷺ) as saying:
When any one of you enters the mosque, he should observe two rak'ahs (of Nafl prayer) before sitting. (Sahih Muslim Book 6 – Hadith 84)
Abu Qatada, a Companion of the Messenger of Allah (ﷺ), said:
I entered the mosque, when the Messenger of Allah (ﷺ) had been sitting among people, and I also sat down among them. Upon this the Messenger of Allah (ﷺ) said: What prevented you from offering two rak'ahs (of Nafl prayer) before sitting down? I said: Messenger of Allah, I saw you sitting and people sitting (around you and I, therefore, sat in your company). He (the Holy Prophet) then said: When anyone among you enters the mosque, he should not sit till he has observed two rak'ahs. (Sahih Muslim Book 6 – Hadith 85)
Jabir b. 'Abdullah reported:
The Apostle of Allah (ﷺ) owed me a debt; he paid me back and made an addition (of this). I entered the mosque and he (the Holy Prophet) said to me: Observe two rak'ahs of prayer. (Sahih Muslim Book 6 – Hadith 86)
Chapter 12: It is recommended to pray two rak`ah in the masjid for one who has come from a journey, when he first arrives.
Jabir b. 'Abdullah reported:
The Messenger of Allah (ﷺ) bought a camel from me. When he came back to Medina, he ordered me to come to the mosque and observed two rak'ahs of prayer. (Sahih Muslim Book 6 – Hadith 87)
Jabir b. 'Abdullah reported:
I went with the Messenger of Allah (ﷺ) on an expedition and my camel delayed me and I was exhausted. The Messenger of Allah (ﷺ) thus came earlier than I, whereas I came on the next day and went to the mosque and found him (the Holy Prophet) at the gate of the mosque. He said: It is now that you have come. I said. Yes. He said: Leave your camel and enter (the mosque) and observe two rak'ahs. He (the narrator) said: So I entered and observed (two rak'ahs) of prayer and then went back. (Sahih Muslim Book 6 – Hadith 88)
Ka'b b. Malik reported:
The Messenger of Allah (ﷺ) did not come back from the journey but by day in the forenoon, and when he arrived, he went first to the mosque, and having prayed two rak'ahs in it he sat down in it. (Sahih Muslim Book 6 – Hadith 89)
Sahih Muslim Book 6 – Hadith 82-89