Sayyiduna Yazid bin ‘Amir (may Allah be pleased with him) narrates: The Prophet (peace and blessings be upon him) said to me: “When you come (to the mosque) for prayer and find the people performing prayer, then perform prayer with them. If you have already performed that prayer, then it will be counted as a voluntary (nafl) prayer for you, and it will be considered as obligatory (fard).”
Hadith Referenceسنن الدارقطني / كتاب الصلاة / 1080
Hadith Takhrij«أخرجه أبو داود فى ((سننه)) برقم: 577، والبيهقي فى((سننه الكبير)) برقم: 3707، والدارقطني فى ((سننه)) برقم: 1080، والطبراني فى((الكبير)) برقم: 624»