Sayyiduna Jabir (may Allah be pleased with him) narrated that a man came to the mosque on Friday while the Prophet (peace and blessings of Allah be upon him) was delivering the sermon. The Prophet asked him, "Have you performed (the Tahiyyat al-Masjid) prayer?" The man replied, "No." The Prophet said, "Stand up and perform two rak‘ahs (of Tahiyyat al-Masjid) prayer."
Hadith Referenceاللؤلؤ والمرجان / كتاب الجمعة / 502
Hadith Gradingمحدثین:«صحیح»
Hadith Takhrij«صحیح، أخرجه البخاري في: 11 كتاب الجمعة: 33 باب من جاء والإمام يخطب صلى ركعتين خفيفتين»
Brief Explanation
Hujjat al-Hind Sayyiduna Shah Wali rahimahullah states that when a worshipper enters the mosque in such a state that the imam is delivering the sermon (khutbah), he should perform two light (khafif) units (rak‘ah) so that both the established sunnah (sunnah ratibah) and the etiquette of the sermon are observed. And regarding this issue, do not be deceived by the commotion (objections) of the people of your city (who prevent it), because in favor of this issue, an authentic hadith has been reported, the following of which is obligatory. (Hujjat Allah al-Balighah: vol. 2, p. 101)