Abu Dharr reported,

The Messenger of Allah ﷺ struck my thigh and said to me, "How will you fare when you live among people who delay the prayer past its proper time?"I asked, "What do you command me to do?"He replied, "Pray the prayer at its proper time, then go about your needs. If the prayer is then called while you are in the mosque, pray with them."

Nasai 860

Sahih

أخبرنا محمد بن عبد الأعلى ومحمد بن إبراهيم بن صدران واللفظ له عن خالد بن الحارث قال حدثنا شعبة عن بديل قال سمعت أبا العالية يحدث عن عبد الله بن الصامت

عن أبي ذر قال

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

النسائي 860صحيح
Contents
Reference
Commentary
Ayat
Collection
Sunan Nasai Sughra
Book
Leadership
Chapter
Repeating the prayer after its time has passed with the congregation
Numbering
Darussalam 860
Nasai 860