The Messenger of Allah ﷺ said, "When one of you enters the mosque, let him pray two rakahs before sitting down."
أن رسول الله ﷺ قال: إذا دخل أحدكم المسجد، فليركع ركعتين قبل أن يجلس.
Malik narrated it in Qasr as-Salah (57) from Amir bin Abdullah bin Zubayr, from Amr bin Salim Zarqi, from Abu Qatada Ansari, who related the same. Bukhari narrated it in as-Salah (444) from Abdullah bin Yusuf, and Muslim narrated it in Salat al-Musafirin (714) from Abdullah bin Maslama, Qutayba bin Saeed, and Yahya bin Yahya, all of them from Malik with the same wording.Muslim also narrated it through another route, from Muhammad bin Yahya bin Habban, from Amr bin Salim bin Khalda Ansari, from Abu Qatada, who said, "I entered the masjid while the Messenger of Allah was sitting among the people." He said, "So I sat down, and the Messenger of Allah said, 'What kept you from praying two rakahs before you sat down?'" He said, "I said, 'Messenger of Allah, I saw you sitting, and the people sitting.'" He said, "So when any of you enters the masjid, let him not sit until he has prayed two rakahs."In the version of Abu Bakr bin Abu Shayba (1/340) and Ibn Khuzayma (1824), the Prophet said, "Give the masajid their due." It was said, "And what is their due?" He said, "Two rakahs before you sit down." This version contains Muhammad bin Ishaq, who is a mudallis, though he has explicitly stated the mode of transmission (tahdith) in the version of Ibn Khuzayma.