I would begin by saying that I don't believe the vision that appeared to Saul through the Witch of Endor was really Samuel. Let me explain this statement.
The Hebrew words for "medium", "spiritists" and so on is b'el owb, which means, "possessing a familiar spirit".
God spoke about the punishment that would come to those who sought the services of such possessed individuals:
"'Do not turn to mediums or seek out spiritists, for you will be defiled by them. I am the LORD your God.'" (Leviticus 19:31, NIV)
"'I will set my face against the person who turns to mediums and spiritists to prostitute himself by following them, and I will cut him off from his people.'" (Leviticus 20:6, NIV)
"'A man or woman who is a medium or spiritist among you must be put to death. You are to stone them; their blood will be on their own heads.' " (Leviticus 20:27, NIV)
He had Moses tell the children of Israel that it was the practices of the original inhabitants of the land of Canaan, such as human sacrifice, divination, sorcery, witchcraft and consulting the dead, that had cause Him to decide that the children of Israel would destroy this people out of their land and take it from them.
"When you enter the land the LORD your God is giving you, do not learn to imitate the detestable ways of the nations there. Let no one be found among you who sacrifices his son or daughter in the fire, who practices divination or sorcery, interprets omens, engages in witchcraft, or casts spells, or who is a medium or spiritist or who consults the dead.
"Anyone who does these things is detestable to the LORD, and because of these detestable practices the LORD your God will drive out those nations before you. You must be blameless before the LORD your God. The nations you will dispossess listen to those who practice sorcery or divination. But as for you, the LORD your God has not permitted you to do so. " (Deuteronomy 18:9-14, NIV)
Although we are not told specifically that the witch of Endor was using the power of Satan to do her "consulting of the dead", we are told that she was possessed with a "familiar spirit", i.e., a demon, and by the scriptures quoted and many others, we know such things DO NOT come from God.
Whatever or whoever it was that Saul saw in his vision, it certainly was not Samuel for Samuel was dead [1Samuel 28:3]. We also know that the dead "know nothing" and have no part "in any thing under the sun".
"For the living know that they will die, but the dead know nothing; they have no further reward, and even the memory of them is forgotten. Their love, their hate and their jealousy have long since vanished; never again will they have a part in anything that happens under the sun. " (Ecclesiastes 9:5-6, NIV)
Whatever or whoever it was that Saul saw in that vision, it (he) told Samuel that Israel was going to lose its battle and that Saul and his sons would be killed and Saul's kingdom handed over to David. That is exactly what happened (see 1Samuel 31:1-6; 2Samuel 1-5). God controls all things. Perhaps He controlled the vision that Saul saw, but I think it more likely that the demon in the witch of Endor took delight in taunting Saul, the King of Israel.