I’m not sure if it is an official teaching, but according to the footnotes for this scripture in the Saint Joseph Version of the NAB, it was God allowing Samuel to appear to King Saul.
My Navarre commentary says: "These ceremonies for evoking spirits do not work; it is Samuel who takes the initiative and appears before Saul as a supernatural spirit (a “spirit of Elohim”) to speak not on his own behalf but in the name of God.
Specifically, it is Sirach 46:20, where Samuel’s after-death appearance to Saul is mentioned:
Even after he had fallen asleep he prophesied
and revealed to the king his death,
and lifted up his voice out of the earth in prophecy,
to blot out the wickedness of the people.
DISCLAIMER: Catholic Answers has turned over the archive to Catholic-Questions.org and no longer owns, manages, or moderates the forums. For additional apologetics resources please visit www.catholic.com.