The site of the Prophet's ﷺ mosque belonged to the Banu al-Najjar. It contained palm trees and graves of polytheists. The Prophet ﷺ said to them, "Name me a price for it."They replied, "We will not take any price for it."The Prophet ﷺ worked on building it while they handed him the materials, and he was saying, "Indeed, true life is the life of the Hereafter, so forgive the Ansar and the Muhajirun."The narrator said, before the mosque was built, the Messenger of Allah ﷺ used to pray wherever the time of prayer overtook him.
حدثنا وكيع حدثنا حماد بن سلمة عن أبي التياح
كان موضع مسجد النبي ﷺ لبني النجار وكان فيه نخل وقبور المشركين فقال لهم النبي ﷺ ثامنوني به فقالوا لا نأخذ له ثمنا وكان النبي ﷺ يبنيه وهم يناولونه وهو يقول ألا إن العيش عيش الآخره فاغفر للأنصار والمهاجره قال وكان رسول الله ﷺ يصلي قبل أن يبنى المسجد حيث أدركته الصلاة
Its isnad is sahih. Abu Tayah is Yazid bin Humayd, and the hadith was narrated by Bukhari 1/117 in the Book of Prayer, chapter on whether the graves of polytheists may be dug up, and by Muslim 1/273 no. 524 in the Book of Masjids, chapter on the building of the masjid of the Prophet ﷺ, and by Abu Dawud 1/124 no. 454, and by Ibn Majah 1/245 no. 742.