كتاب الجمعة
7  
The Book of Prayer - Friday
(14)
Chapter: Greeting (prayers upon entering the masjid) while the Imam is preaching
(14)
باب التَّحِيَّةِ وَالإِمَامُ يَخْطُبُ ‏
Sahih Muslim 875 c

Jabir b. 'Abdullah said that a person entered the Mosque while the Messenger of Allah (ﷺ) was delivering the sermon on Friday. Upon this he (the Holy Prophet) said:

Have you observed prayer? He said: No. He (the Holy Prophet) said: Stand and offer the two rak'ahs. According to Qutaiba, the words are:" He said: Offer two rak'ahs."
وَحَدَّثَنَا قُتَيْبَةُ بْنُ سَعِيدٍ، وَإِسْحَاقُ بْنُ إِبْرَاهِيمَ، قَالَ قُتَيْبَةُ حَدَّثَنَا وَقَالَ، إِسْحَاقُ أَخْبَرَنَا سُفْيَانُ، عَنْ عَمْرٍو، سَمِعَ جَابِرَ بْنَ عَبْدِ اللَّهِ، يَقُولُ دَخَلَ رَجُلٌ الْمَسْجِدَ وَرَسُولُ اللَّهِ صلى الله عليه وسلم يَخْطُبُ يَوْمَ الْجُمُعَةِ فَقَالَ ‏"‏ أَصَلَّيْتَ ‏"‏ ‏.‏ قَالَ لاَ ‏.‏ قَالَ ‏"‏ قُمْ فَصَلِّ الرَّكْعَتَيْنِ ‏"‏ ‏.‏ وَفِي رِوَايَةِ قُتَيْبَةَ قَالَ ‏"‏ صَلِّ رَكْعَتَيْنِ ‏"‏ ‏.‏
Reference : Sahih Muslim 875c
In-book reference : Book 7, Hadith 70
USC-MSA web (English) reference : Book 4, Hadith 1899
  (deprecated numbering scheme)