He prayed with the Messenger of Allah ﷺ when he was a young lad. After the prayer ended, he noticed two men in a corner of the mosque who had not prayed. The Prophet ﷺ called for them, and they were brought to him trembling.He asked, "What kept you from praying with us?"They replied, "We had already prayed at our lodgings."He said, "Do not do that. When one of you prays at his lodging and then comes upon the imam before he has prayed again, let him pray with the imam, for it will count as a voluntary prayer for him."
حدثنا حفص بن عمر حدثنا شعبة أخبرني يعلى بن عطاء
أنه صلى مع رسول الله ﷺ وهو غلام شاب فلما صلى إذا رجلان لم يصليا في ناحية المسجد فدعا بهما فجئ بهما ترعد فرائصهما فقال ما منعكما أن تصليا معنا قالا قد صلينا في رحالنا فقال لا تفعلوا إذا صلى أحدكم في رحله ثم أدرك الإمام ولم يصل فليصل معه فإنها له نافلة
[Its isnad is sahih]. Tirmidhi narrated it in the Book of Prayer, chapter on a man who prays alone and then catches up with the congregation, hadith 219, from the hadith of Yaala bin Ata as above, and he said, hasan sahih. Ibn Khuzayma graded it sahih, hadith 1279, as did Ibn Hibban, hadith 434, 435, and Nasai narrated it, hadith 859.