Sunan Abi Dawud Book 2, Hadith 64
The Mosque (of the Prophet) was built in the land of Banu al-Najjar which contained crops, palm trees and graves of the disbelievers. The Messenger of Allah (ﷺ) said: Sell it to me for some price. They (Banu al-Najjar) replied: We do not want (any price). The palm-trees were cut off, and the crops removed and the graves of the disbelievers dug opened. He then narrated the rest of the tradition. But this version has the word "forgive" in the verse, instead of the word "help". Musa said: 'Abd al-Warith also narrated this tradition in a like manner. The version of 'Abd al-Warith has the word "dung-hill" (instead of crop), and he asserted that he narrated this tradition to Hammad.
Messenger of Allah (ﷺ) came over to Medina and encamped at the upper side of Medina among the tribe known as Banu 'Amr b. 'Awf. He stayed among them for fourteen days. He then sent someone to call Banu al-Najjar. They came to him hanging their swords from the necks. Anas then said: As if I am looking at the Messenger of Allah (ﷺ) sitting on his mount and Abu Bakr seated behind him, and Banu al-Najjar standing around him. He descended in the courtyard of Abu Ayyub. The Messenger of Allah (ﷺ) would say his prayer in the folds of the sheep and goats. He commanded us to build a mosque. He then sent for Banu al-Najjar and said to them: Banu al-Najjar, sell this land of yours to me for some price. They replied: By Allah, we do not want any price (from you) except from Allah. Anas said: I tell what this land contained. It contained the graves of the disbelievers, dung-hills, and some trees of date-palm. The Messenger of Allah (ﷺ) commanded and the graves of the disbelievers were dug open, and the trees of the date-palm were cut off. The wood of the date-palm were erected in front of the mosque ; the door-steps wre built of stone. They were reciting verses carrying the stones. The Prophet (ﷺ) also joined them (in reciting verses) saying: O Allah, there is no good except the good of the Hereafter. So grant you aid to the Ansar and the Muhajirah.
The Messenger of Allah (ﷺ) commanded us to build mosques in different localities (i.e. in the locality of each tribe separately) and that they should be kept clean and be perfumed.