حَدَّثَنَا عَلِيُّ بْنُ عَبْدِ اللَّهِ، قَالَ حَدَّثَنَا سُفْيَانُ، عَنْ عَمْرٍو، سَمِعَ جَابِرًا، قَالَ دَخَلَ رَجُلٌ يَوْمَ الْجُمُعَةِ وَالنَّبِيُّ صلى الله عليه وسلم يَخْطُبُ فَقَالَ ‏"‏ أَصَلَّيْتَ ‏"‏‏.‏ قَالَ لاَ‏.‏ قَالَ ‏"‏ فَصَلِّ رَكْعَتَيْنِ ‏"‏‏.‏
Translation
Narrated Jabir

A man entered the Mosque while the Prophet (ﷺ) was delivering the Khutba. The Prophet (ﷺ) said to him, "Have you prayed?" The man replied in the negative. The Prophet (ﷺ) said, "Pray two rak`at."

Comment

The Excellence of Friday Prayer

This narration from Sahih al-Bukhari (931) establishes the fundamental ruling that one who enters the mosque during the Friday sermon must perform two rak'at of tahiyyat al-masjid (greeting the mosque) before sitting, even during the khutbah.

Scholarly Commentary

Imam al-Nawawi explains in his commentary that this hadith demonstrates the superiority of the prayer over listening to the khutbah when one first enters the mosque. The tahiyyat al-masjid takes precedence due to its established virtue in multiple authentic narrations.

Ibn Hajar al-Asqalani in Fath al-Bari clarifies that this ruling applies specifically to the Friday prayer scenario, where even during the obligatory khutbah, the sunnah of greeting the mosque remains valid and recommended.

The wisdom behind this ruling, as explained by classical scholars, includes showing respect to the mosque, following the Prophet's sunnah, and preparing one's heart for worship before engaging in the congregational prayer.

Juridical Ruling

The majority of scholars from the Shafi'i, Maliki, and Hanbali schools consider tahiyyat al-masjid to be a confirmed sunnah (sunnah mu'akkadah) based on this hadith. The Hanafi school regards it as mustahabb (recommended).

This ruling applies to all times of entering the mosque, but its importance is emphasized during the Friday congregation when many might neglect it due to the ongoing khutbah.