The Messenger of Allah ﷺ said, "Whoever performs ablution well and then sets out heading to the mosque only to find that the people have already prayed, Allah will record for him a reward equal to the reward of those who attended the prayer, without diminishing their rewards in the slightest."
أخبرنا إسحق بن إبراهيم قال حدثنا عبد العزيز بن محمد عن ابن طحلاء عن محصن بن علي الفهري عن عوف بن الحارث
عن رسول الله ﷺ قال من توضأ فأحسن الوضوء ثم خرج عامدا إلى المسجد فوجد الناس قد صلوا كتب الله له مثل أجر من حضرها ولا ينقص ذلك من أجورهم شيئا
[Hasan] Abu Dawud narrated it in the Book of Prayer, in the chapter "On one who sets out intending to pray but finds the prayer has already been completed," hadith no. 564, from the hadith of Abdul-Aziz Darawardi with this wording. It is also found in Sunan al-Kubra, hadith no. 928. Hakim declared it sahih in 1/208-209, as did Dhahabi, and it has corroborating narrations.