The vision that appeared to Saul through the Witch of Endor was NOT really Samuel. The Hebrew words for "medium", "spiritists" and so on is b'elowb, which means "possessing a familiar spirit." God spoke about what he thought about such people and warned others not to consult them.
Do not go for advice to people who consult the spirits of the dead. (Leviticus 19:31, see also 20:6)
27 Any man or woman who consults the spirits of the dead shall be stoned to death; (Leviticus 20:27)
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 (Deuteronomy 18:9 - 14)
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" (see Ecclesiastes 9:5 - 6).
Whatever or whoever it was that Saul saw in that vision, it (he) told Samuel that Israel was going to lose its battle, Saul and his sons would be killed, and Saul's kingdom would be 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.