Anas bin Malik reported,

The Prophet ﷺ arrived in Madinah and stayed in the upper part of the city among a tribe called Banu Amr bin Awf. He remained with them for fourteen nights, then sent word to Banu al-Najjar, who came wearing their swords. It is as though I can still see the Prophet ﷺ on his mount, with Abu Bakr riding behind him and the elders of Banu al-Najjar surrounding him, until he dismounted in the courtyard of Abu Ayub.He used to love to pray wherever the time of prayer caught him, and he would pray in the resting places of sheep. He gave orders that a mosque be built, so he sent for the chiefs of Banu al-Najjar and said, "Banu al-Najjar, name me a price for this orchard of yours."They replied, "No, by Allah, we will seek its price only from Allah."Anas said, "There were in it, as I am telling you, graves of polytheists, ruins, and date palms. The Prophet ﷺ ordered that the graves of the polytheists be exhumed, the ruins leveled, and the palm trees cut down. They lined up the palm trunks as the qiblah of the mosque and made its doorposts of stone. They began carrying the rocks while chanting, with the Prophet ﷺ alongside them, saying, 'O Allah, there is no good except the good of the hereafter, so forgive the Ansar and the Muhajirun.'"

Azami 3091

Sahih

عن أنس قال

قدم النبي ﷺ المدينة فنزل أعلى المدينة في حي يقال لهم بنو عمرو بن عوف، فأقام النبي ﷺ فيهم أربع عشرة ليلة، ثم أرسل إلى بني النجار فجاءوا متقلدي السيوف، كأني أنظر إلى النبي ﷺ على راحلته وأبو بكر ردفه وملأ بني النجار حوله، حتى ألقى بفناء أبي أيوب، وكان يحب أن يصلي حيث أدركته الصلاة ويصلي في مرابض الغنم، وأنه أمر ببناء المسجد، فأرسل إلى ملإ من بني النجار فقال: يا بني النجار ثامنوني بحائطكم هذا، قالوا: لا والله لا نطلب ثمنه إلا إلى الله، فقال أنس: فكان فيه ما أقول لكم: قبور المشركين، وفيه خرب، وفيه نخل، فأمر النبي ﷺ بقبور المشركين فنبشت، ثم بالخرب فسويت، وبالنخل فقطع، فصفوا النخل قبلة المسجد، وجعلوا عضادتيه الحجارة، وجعلوا ينقلون الصخر وهم يرتجزون، والنبي ﷺ معهم وهو يقول: اللهم لا خير إلا خير الآخرة فاغفر للأنصار والمهاجرة.

الأعظمي 3091صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Mosques
Section
Exhuming graves and building mosques over them
Numbering
Jami al-Kamil 3091 (2nd edition)
Azami 3091