Had the soil of the idolaters’ graves been impure, the Prophet—peace and blessings be upon him—would certainly have ordered that earth to be removed, for it would inevitably become mixed with the surrounding ground.
The second rationale is that praying at graves resembles the practice of the unbelievers and leads to idolatry; this argument is unanimously accepted.
Those who cite the first rationale—such as al-Shāfiʿī and others—also invoke the second, deeming the practice reprehensible because of the potential for temptation. The same applies to the leading scholars of the Mālikī and Ḥanbalī schools, among them Abū Bakr al-Athram, a close disciple of Aḥmad; they, too, rely on this second reason, even though some of them also mention the first.
God Most High says: “And they said, ‘Do not abandon your gods; do not abandon Wadd, nor Suwāʿ, nor Yaghūth, Yaʿūq, and Nasr.’” (Sūrat Nūḥ, 23)
Ibn ʿAbbās and other early authorities explained: “These were the names of righteous men among the people of Noah. When they died, their people remained devoted to their graves and fashioned images of them; in time, they came to worship them.” This report is recorded by al-Bukhārī in his Ṣaḥīḥ, by the Qur’ānic commentators such as Ibn Jarīr and others, and by the authors of prophetic stories such as Wathīmah.
The soundness of this rationale is further confirmed by the fact that the Prophet, peace and blessings be upon him, cursed those who turn the graves of the prophets into places of worship; and it is well known