Does it say anything in the Tanach or in the Talmud about talking to the dead through a medium?
In I Samuel 28 there is told the story of King Saul going to a medium in order to be able to consult with the prophet Samuel who had died recently. The medium succeeded in bringing up Samuel, and he spoke with King Saul. The verses show that the medium was quite shocked when she saw Samuel which seems surprising as she was an experienced medium. Our sages explain that her surprise was due to the fact that he came up right-side-up, and the dead usually rise upside-down.
The Talmud (Shabbos 152b) tells us that a non-believer once asked Rebbe Avahu how it was that Saul was able to bring up Samuel if the souls of the righteous are under the Throne of Glory. He responded that within 12 months of death one is able to bring up even the righteous.
From this response it would seem as if the medium has the power to do it during that time period, even if the deceased soul doesn’t want.
The Kabbalistic commentators take this statement further. The Talmud is explaining the success of causing Samuel to rise, but why was he right side up? The Radvaz explains that since there was nothing Samuel could do to prevent himself from being brought up, he was facing a very uncomfortable situation. Coming up in this manner is a result of the medium using powers of impurity (Tumah), and to be forced to come up by such methods would have been devastating to a holy man like Samuel. Therefore, seeing the inevitable, he came up instead through the power of prophecy which is holy, in order to preempt being brought up through impurity. This is why he came up right side up, in a respecful manner befitting holiness, and not upside down which is a manner befitting impurity. He then told Saul the prophecy he had for him.
The Arizal, who asks how it is that a holy person like Samuel can be affected and controlled by powers of impurity. He explains that there are five levels of the soul. The medium can only bring up the lowest, least holy, level.
I hope this has shed some light on your question.
