I asked, "Messenger of Allah, which mosque was established on earth first?"He replied, "The Sacred Mosque."I asked, "Then which?"He said, "Masjid al-Aqsa."I asked, "How long was there between them?"He said, "Forty years. Then wherever the time of prayer overtakes you afterwards, pray there, for the merit lies in it."
قلت: يا رسول الله! أي مسجد وضع في الأرض أول؟ قال: المسجد الحرام قال: قلت: ثم أي؟ قال: المسجد الأقصى قلت: كم كان بينهما؟ قال: أربعون سنة. ثم أينما أدركتك الصلاة بعد، فصله، فإن الفضل فيه.
Bukhari related it in the chapters on the prophets (3366), and Muslim in the chapter on mosques (520), both from the hadith of Abdul-Wahid, from Amash, who said, Ibrahim Taymi narrated to us, from his father, who said, I heard Abu Dharr, and he mentioned it. See the commentary on this hadith in the tafsir of Surah Isra.His saying, "and purify My house", means purify it of shirk, sins, filth, and impurities, and set it apart exclusively for those mentioned, those who circle it, those who stand, and those who bow and prostrate. When Quraysh introduced into this house the worship of other than Allah, and set up idols in it, including the idol of Ibrahim and Ismail, peace be upon them, the Prophet ﷺ undertook to purify this house from the worship of anything other than Allah and to restore it to the worship of Allah alone for those who circle it, those who stand, and those who bow and prostrate. And in this way Allah completed the covenant He had taken from Ibrahim .