Indeed, one of the earliest roots of idol-worship is to linger devotedly at the graves of prophets and the righteous and to remain before their statues, even though idolatry has sometimes arisen in other ways.
Allah recounts about the polytheists:
“Do not abandon your gods; do not abandon Wadd, Suwāʿ, Yaghūth, Yaʿūq, or Nasr— they have already misled many.” 1
A number of early scholars related that these were righteous men; when they died, their people built structures over their graves and then fashioned images of them.
Similarly, Ibn ʿAbbās, commenting on the verse, “Have you considered al-Lāt and al-ʿUzzā, and Manāt, the third—the other one?” 2, said: “Al-Lāt was a man who used to prepare barley porridge for the pilgrims. When he died, the people began to gather at his grave.” For that reason the Prophet ﷺ said, “O Allah, do not let my grave become an idol that is worshiped,” and he forbade performing prayer at his grave.
Therefore, when the Muslims later enclosed his chamber, they angled its rear wall and raised it so that no one would pray toward it. 3 He ﷺ also said, “Do not sit on graves, and do not pray toward them,” 4 as narrated by Muslim.
Whenever he ﷺ visited the people of al-Baqīʿ, he would greet them and supplicate for them.