´It was narrated from Abu Hurairah that the Messenger of Allah (ﷺ) said:` “When anyone of you enters the mosque, let him not sit down until he performs two Rak’ah.”
Hadith Referenceسنن ابن ماجه / كتاب إقامة الصلاة والسنة / 1012
Hadith Gradingالألبانی:صحيح لغيره | زبیر علی زئی:صحيح
Hadith Takhrij«تفرد بہ ابن ماجہ، ( تحفة الأشراف: 14615، ومصباح الزجاجة: 364 ) ( صحیح ) ( شواہد سے تقویت پاکر یہ حدیث صحیح ہے، ورنہ اس کی سند میں مطلب بن عبداللہ، اور ابو ہریرہ رضی اللہ عنہ کے درمیان انقطاع ہے، ملاحظہ ہو: مصباح الزجاجة: والإرواء: 467، و صحیح ابی داود: 486 )»
Brief Explanation
1؎: That is, he should perform two units (rak‘ahs) of the greeting of the mosque (tahiyyat al-masjid), and if he begins any other sunnah or obligatory (fard) prayer upon entering, then the greeting of the mosque will be fulfilled, and there will be no need to perform it separately. From this hadith, it is understood that when one enters the mosque, he should perform two rak‘ahs, and this ruling is general and inclusive of every situation. Thus, even if the imam is delivering the sermon (khutbah) and someone enters the mosque at that time, he should still perform two rak‘ahs before sitting down. This is explicitly stated in the hadith of Sulaik Ghatafani radi Allahu anhu, and this is the position of the Ahl al-Hadith.