Ibrahim bin Yazid Taymi reported,

I used to recite the Quran to Ubayy in the vestibule. Whenever I recited a verse of prostration, he would prostrate.I said to him, "Father, do you prostrate in the road?"He replied, "I heard Abu Dharr say, 'I asked the Messenger of Allah ﷺ about the first mosque established on earth.'He said, 'The Sacred Mosque.'I asked, 'Then which?'He said, 'The Aqsa Mosque.'I asked, 'How long between the two?'He said, 'Forty years. Then the whole earth is a mosque for you, so wherever the time of prayer overtakes you, pray.'"

Muslim 1162

Sahih

حدثني علي بن حجر السعدي أخبرنا علي بن مسهر حدثنا الأعمش

عن إبراهيم بن يزيد التيمي قال

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

مسلم 1162صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Muslim
Book
Mosques and places of prayer
Chapter
Mosques and places of prayer
Numbering
Darussalam 1162
Muslim 1162