This excerpt is taken from Sheikh al-Islam Imam Ibn Taymiyyah's book Al-Jawab al-Bahir fi Zuwar al-Maqabir, translated by Sheikh Ataullah Saqib.
Difference between the visitation of graves by a monotheist and a polytheist:
The Holy Prophet Muhammad (peace be upon him), while explaining the difference between the ways of visiting graves of the people of monotheism and the polytheists, said that when the people of monotheism go to visit graves, they pray for the deceased, send salutations, and ask for forgiveness, as is done in the funeral prayer. But when a polytheist goes to a cemetery, he equates the creation with the Creator, offers gifts in the name of the deceased, prostrates to them, calls upon them as if they are the ones who relieve difficulties, and expresses love for them as one would love Allah Almighty. Thus, through his actions, he makes the people of the graves partners with Allah Almighty and equal to Him. However, Allah Almighty has strictly forbidden people from associating partners with Him, such as prophets or angels. Accordingly, Allah Almighty says:
مَا كَانَ لِبَشَرٍ أَن يُؤْتِيَهُ اللَّهُ الْكِتَابَ وَالْحُكْمَ وَالنُّبُوَّةَ ثُمَّ يَقُولَ لِلنَّاسِ كُونُوا عِبَادًا لِّي مِن دُونِ اللَّهِ وَلَٰكِن كُونُوا رَبَّانِيِّينَ بِمَا كُنتُمْ تُعَلِّمُونَ الْكِتَابَ وَبِمَا كُنتُمْ تَدْرُسُونَ ﴿٧٩﴾ وَلَا يَأْمُرَكُمْ أَن تَتَّخِذُوا الْمَلَائِكَةَ وَالنَّبِيِّينَ أَرْبَابًا ۗ أَيَأْمُرُكُم بِالْكُفْرِ بَعْدَ إِذْ أَنتُم مُّسْلِمُونَ ﴿٨٠﴾
“It is not for any human being that Allah should give him the Scripture and authority and prophethood and then he would say to the people, ‘Be my servants rather than Allah’s.’ Rather, he would say, ‘Be devoted servants of the Most Merciful, because you have taught and read this Book.’ He would never say to the people, ‘Take me and my angels and my prophets as lords besides Allah.’ Is it possible for a prophet to command you to disbelieve while you are Muslims?”
Reference: (3-Al Imran:79-80)
They themselves are hopeful:
❀ At another place, the Divine command is:
قُلِ ادْعُوا الَّذِينَ زَعَمْتُم مِّن دُونِهِ فَلَا يَمْلِكُونَ كَشْفَ الضُّرِّ عَنكُمْ وَلَا تَحْوِيلًا ﴿٥٦﴾ أُولَٰئِكَ الَّذِينَ يَدْعُونَ يَبْتَغُونَ إِلَىٰ رَبِّهِمُ الْوَسِيلَةَ أَيُّهُمْ أَقْرَبُ وَيَرْجُونَ رَحْمَتَهُ وَيَخَافُونَ عَذَابَهُ ۚ إِنَّ عَذَابَ رَبِّكَ كَانَ مَحْذُورًا ﴿٥٧﴾
"Say, call upon those whom you claim besides Allah; they do not remove any distress from you, nor can they change it. Those whom they call upon are themselves seeking a way to approach their Lord, to be nearer to Him, hoping for His mercy and fearing His punishment. Indeed, the punishment of your Lord is something to be feared."
Reference: (17-Al-Isra:56-57)
Regarding this verse, a group of the Salaf held the view that many nations and peoples of the past used to call upon their prophets, such as Prophet Jesus (peace be upon him), Prophet Uzair (peace be upon him), and similarly angels during times of hardship and trials, hoping to be delivered from difficulties and calamities. Allah Almighty warned His nations that these were My servants who themselves sought My mercy, feared My punishment, and strove to attain My closeness through righteous deeds.