Concerning one who enters the mosque while the Imam is delivering the sermon
حَدَّثَنَا هِشَامُ بْنُ عَمَّارٍ، حَدَّثَنَا سُفْيَانُ بْنُ عُيَيْنَةَ، عَنْ عَمْرِو بْنِ دِينَارٍ، سَمِعَ جَابِرًا، وَأَبُو الزُّبَيْرِ، سَمِعَ جَابِرَ بْنَ عَبْدِ اللَّهِ، قَالَ دَخَلَ سُلَيْكٌ الْغَطَفَانِيُّ الْمَسْجِدَ وَالنَّبِيُّ ـ صلى الله عليه وسلم ـ يَخْطُبُ . فَقَالَ " أَصَلَّيْتَ؟ " . قَالَ: لاَ . قَالَ " فَصَلِّ رَكْعَتَيْنِ " . وَأَمَّا عَمْرٌو فَلَمْ يَذْكُرْ سُلَيْكًا .
It was narrated that Jabir bin ‘Abdullah said: “Sulaik Ghatafani entered the mosque when the Prophet (ﷺ) was delivering the sermon. He said: ‘Have you prayed?’ He said: ‘No.’ He said: ‘Then perform two Rak’ah.’”