Jabir bin Yazid reported,

I was present with the Prophet ﷺ during his pilgrimage and prayed the dawn prayer with him at the Mosque of Khayf. When he finished his prayer and turned, he noticed two men at the back of the gathering who had not prayed with him. He said, "Bring them to me."They were brought forward, trembling with fear.He asked them, "What kept you from praying with us?"They replied, "Messenger of Allah, we had already prayed at our camp."He said, "Do not do that. If you have prayed at your camp and then come to a mosque where the congregation is praying, pray with them, for it will count as a voluntary prayer for you."

Tirmidhi 219

Sahih

حدثنا أحمد بن منيع حدثنا هشيم أخبرنا يعلى بن عطاء حدثنا

جابر بن يزيد بن الأسود العامري عن أبيه قال

شهدت مع النبي ﷺ حجته فصليت معه صلاة الصبح في مسجد الخيف قال فلما قضى صلاته وانحرف إذا هو برجلين في أخرى القوم لم يصليا معه فقال علي بهما فجيء بهما ترعد فرائصهما فقال ما منعكما أن تصليا معنا فقالا يا رسول الله إنا كنا قد صلينا في رحالنا قال فلا تفعلا إذا صليتما في رحالكما ثم أتيتما مسجد جماعة فصليا معهم فإنها لكما نافلة

الترمذي 219صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami Tirmidhi
Book
Prayer
Chapter
Man who prays alone then catches the congregation
Numbering
Darussalam 219
Tirmidhi 219