Can You Talk to The Dead in Islam?
Question

Is speaking to a dead person haram or even shirk? I don’t mean praying or seeking help, I mean only to speak to a dead person and can you give proofs from the Quran and Sunnah.
Praise be to Allah.What Is Permissible When Visiting Graves in Islam?
What is prescribed when visiting graves is to greet the dead with Salam and offer supplication for them, not to talk to them.
Muslim (975) narrated that Buraydah (may Allah be pleased with him) said: The Messenger of Allah (blessings and peace of Allah be upon him) used to teach them, when they went out to the graves, to say: Peace be upon you, O people of these abodes, believers and Muslims, and we will, if Allah wills, join you soon. I ask Allah for wellbeing for us and for you.”
According to a report narrated by An-Nasa’i, when the Messenger of Allah (blessings and peace of Allah be upon him) came to the graveyard, he would say: “Peace be upon you, O people of these abodes, believers and Muslims. Indeed we, if Allah wills, will join you soon. You have gone ahead of us and we will join you. I ask Allah for wellbeing for us and for you.”
Can Muslims Speak to the Deceased?
Regardless of whether it is said that the dead can hear or not hear, talking to them as one talks to those who are living is not mentioned in the reports. Moreover, it is a door that leads to a number of bad things, such as becoming attached to them and addressing one’s worries and concerns to them, and perhaps that would lead to believing that they know the unseen, or it would lead to calling upon them and asking of them.
If speaking to the dead was a good thing, the Prophet (blessings and peace of Allah be upon him) and his companions would have done that before us. Allah, may He be Exalted, Says (interpretation of the meaning):
{This day I have perfected for you your religion and completed My favor upon you and have approved for you Islam as religion.} [Al-Ma’idah 5:3]
Ibn Al-Majishun (may Allah have mercy on him) said: I heard Malik say: Whoever introduces an innovation into Islam, thinking that it is good, is claiming that Muhammad (blessings and peace of Allah be upon him) betrayed the trust, because Allah Says: {This day I have perfected for you your religion.} [Al-Ma’idah 5:3] So whatever was not part of the religion on that day cannot be part of the religion today.” (End quote from Al-I`tisam by Ash-Shatibi 1/64)
The Correct Way to Interact with the Dead According to Islam
Based on that, the one who visits graves should adhere to what is mentioned in the religious texts, so he should greet the occupants with Salam and offer supplication for them, then leave.
If it so happens that someone does speak to the deceased, it cannot be said that it is an act of polytheism or that it is prohibited; rather it may be said that it is not prescribed and it may lead to that which is prohibited, so the best is to refrain from doing that.
For more details, please the following answers: 147920, 13183, 20820, 34361.
And Allah knows best.