By forbidding occult contact with the supernatural realm, what the Church is forbidding are the methods and techniques generally used to “summon up” departed human beings or other spirits (e.g., ouija boards, crystal balls, seances, mediums, etc.). It is not forbidding “conversation,” so to speak, between those in this life and those in the next; it is only forbidding attempts to manipulate the supernatural realm in order to obtain forbidden power or knowledge (CCC 2116).
Take, for example, Saul’s attempt to speak with the dead prophet, Samuel, through the medium of Endor (1 Sam. 28:7-20). It was not Saul’s desire to speak with Samuel that was his sin but the forbidden means by which he accomplished it. It would have been perfectly fine for Saul to have prayed to Samuel, asking Samuel for his intercession; but instead Saul had a medium “conjure” Samuel. The text gives us no reason to think that the person with whom Saul spoke was not Samuel – demonstrating that God may allow such contact to “work” in order to bring good out of evil (in this case, the warning to Saul that he would soon die and had better make ready to do so) – but that does not make the forbidden methods lawful.
Prayer to saints, on the other hand, in entirely different. There is no attempt to conjure up spirits; no attempt to seek forbidden knowledge. All that is done is that the petitioner honors God’s friend and asks the saint for prayer. For more information, please see the articles linked below.
Praying to the Saints
The Intercession of the Saints
Any Friend of God’s Is a Friend of Mine by Patrick Madrid