Sayyiduna Yazid bin al-Aswad al-Khuza'i (may Allah be pleased with him) said: We prayed the Fajr prayer with the Messenger of Allah (peace and blessings be upon him) at Mina. When he (peace and blessings be upon him) had finished the prayer, he saw two men sitting at the back of the mosque. He (peace and blessings be upon him) had them called; they were brought, and they were frightened. He (peace and blessings be upon him) asked: "Why did you not offer the prayer with us?" They said: O Messenger of Allah! We have prayed at home before coming. He (peace and blessings be upon him) said: "Do not do so. When one of you has prayed at home and then catches the congregational prayer with the imam, let him pray it again with the imam; it will be a voluntary prayer for him."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 3645