Jundab bin Abdullah reported,

I heard the Messenger of Allah ﷺ say, five days before he died, "Those who came before you used to take the graves of their prophets and righteous ones as places of worship. Do not take graves as places of worship. I forbid you from that."

Azami 3096

Sahih

عن جندب بن عبد الله البجلي قال

سمعت رسول الله ﷺ قبل أن يموت بخمس وهو يقول: ألا وإن من كان قبلكم كانوا يتخذون قبور أنبيائهم وصالحيهم، مساجد، ألا فلا تتخذوا القبور مساجد إني أنهاكم عن ذلك.

الأعظمي 3096صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Mosques
Section
Prohibition of taking a grave as a masjid
Numbering
Jami al-Kamil 3096 (2nd edition)
Azami 3096