Can building shrine over a grave such that some of the people (if not all) would also worship it be akin to building a pagan idol?
The question stems from the hadith where the prophet pbuh explicitly equated this act to idol building:
Prophet (pbuh) said : Do not make my grave an idol
In the book al-Jaami’ li’l-Bayaan by Ibn Rushd it says:
Maalik (may Allaah have mercy on him) was asked about a stranger who comes to the grave of the Prophet (peace and blessings of Allaah be upon him) each day. He said, That is not right, and quoted the hadeeth:
"O Allaah, do not make my grave an idol that is worshipped."
Classed as saheeh by al-Albaani in Tahdheer al-Saajid min Ittikhaadh al-Quboor Masaajid, p. 24-26.
Ibn Rushd said:
So he regarded it as makrooh to pass by it a great deal to send salaam on him, and to come there every day, lest the grave become like a mosque to which people come every day to pray.
The Messenger of Allaah (peace and blessings of Allaah be upon him) forbade that when he said, "O Allaah, do not make my mosque an idol."
See al-Bayaan wa’l-Tahseel by Ibn Rushd, 18/444-445.
Al-Qaadi ‘Iyaad was asked about people of Madeenah who stand by the grave one or more times a day, and they send salaams and make du’aa’ for a while. He said, “I have not heard of this from any of the fuqaha’, and nothing is good for the latter generations of this ummah except that which was good for its first generations. I have not heard that any of the first generations of the ummah used to do that.” Al-Shifa bi Ta’reef Huqooq al-Mustafa, 2/676.
so the prophet pbuh seems to associate the idea of building something over his grave as building an idol that the reason he says not to make his grave an idol that could be worshiped.
This point is worth noting since in many pagan influenced countries like India, Iran, Israel, and Pakistan. some Muslims have built shrines over the graves of saintly people and over time the shrines have become exotic and generously decorated with gold and jewels making the shrines magnanimous . Such shrines also attract non-Muslims/disbelievers who actually perceive the shrine as an idol to be worshiped in a similar way as the idolaters worship their idols. You can see the pictures below as how the non Muslims are making offerings to their shrine idol.

This is very common in India where the shrines receive up to 40% visitors from the non Muslims and the "Muslims" caretakers of the shrine accept donations and offerings to the shrine. In fact it is very common for disbeliever and outright vulgar Bollywood stars to visit the idol shrine of khawaja ajmer chisti in rajasthan, India.
These disbelievers would also never come to the Mosque or pray to one God but prefer to remain in the status quo of idolatry
