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."
سمعت رسول الله ﷺ قبل أن يموت بخمس وهو يقول: ألا وإن من كان قبلكم كانوا يتخذون قبور أنبيائهم وصالحيهم، مساجد، ألا فلا تتخذوا القبور مساجد إني أنهاكم عن ذلك.
Muslim narrated it in the Book of Mosques (532) via Ubaydullah bin Amr, from Zayd bin Abu Unaysa, from Amr bin Mura, from Abdullah bin Harith Najrani, who said, Jundab told me, saying, I heard the Prophet ﷺ, and he related it in a longer hadith that will come in the virtues of Abu Bakr, "If I were to take a close friend from my nation, I would have taken Abu Bakr as a close friend."