The Zohar III 71a (quoted in Maanah Lashon, the traditional text recited at a Tzaddik's Kever) writes:
אמר רבי ייסא בשעתא דאצטריך עלמא למטרא אמאי אזלינן לגביהון דמיתייא והא כתיב
דורש אל המתים ואסיר. אמר ליה עד כען לא חמיתא גדפא דצפרא דעדן. ודורש אל המתים אל המתים דייקא. דאינון חייבי עלמא דאינון מעמין עכו"ם דאשתכחו תדיר מתים. אבל ישראל דאינון זכאי קשוט שלמה קרא עלייהו ושבח אני את המתים שכבר מתו בזמנא אחרא ולא השתא. שכבר מתו. והשתא אינון חיין. ועוד דשאר עמין כד אתאן למתיהון אתיין בחרשין לאתערא עלייהו זינין בישין. וכד ישראל אתאן למתיהון אתיין בכמה תשובה לקמי קב"ה. בתבירו דלבא. בתעניתא לקבליה וכלא בגין דנשמתין קדישין יבעון רחמי לקמי קב"ה עלייהו וקב"ה חייס על עלמא בגיניהון. וע"ד תנינן צדיקא אע"ג דאתפטר מהאי עלמא לא אסתלק ולא אתאביד מכלהו עלמין דהא בכלהו עלמין אשתכח יתיר מחייוי. דבחייוי אשתכח בהאי עלמא בלחודוי ולבתר אשתכח בתלת עלמין וזמין לגבייהו דכתיב עלמות אהבוך אל תקרי עלמות אלא עולמות זכאה חולקהון.
"R. Yeissa asked: 'Why, when rain is needed for the world, do we go [and pray] at [the resting place of] the dead? For the Torah forbids [us to] "inquire of the dead."'
"He replied: 'You have not yet seen the wing of the Bird of Eden.'. The 'dead' to whom the verse refers are those who may certainly be termed dead, i.e., the sinners* of the heathen who are forever dead. But of Israel who are truly righteous, Solomon says: "And I praise the dead, for they are already dead"; i.e., they have died in the past, but now they are living.
"'Furthermore, when other peoples visit their dead, they come with magic to arouse evil spirits upon themselves. When, by contrast, the Jews visit their dead, they come in profuse repentance before the Holy One, blessed be He, with a contrite heart and with fasting. This is all with the intent that the holy Neshamos entreat the Holy One, blessed be He, for mercy on their behalf — and then, for their sake, He has compassion on the world.
"'In regard to this, we have learnt: A righteous man even when he departs from this world, does not [truly] rise above or vanish from any world. For he is to be found in all worlds more than in his lifetime. In his lifetime, he is found only in this [material] world, but afterwards, he is found in three worlds, and accessible therein. This is alluded to by the verse, "Young maidens (עלמות) love you." Do not read עלמות , "young maidens," but rather עולמות , "worlds." Happy is their lot.'"
(Translation from Chabad.org)
*Note, that the Gemara in Brachos (18b) says (similarly):
והא כתיב (קהלת ט, ה) והמתים אינם יודעים מאומה אמר ליה אם קרית לא שנית אם שנית לא שלשת אם שלשת לא פירשו לך (קהלת ט, ה) כי החיים יודעים שימותו אלו צדיקים שבמיתתן נקראו חיים שנאמר (שמואל ב כג, כ) ובניהו בן יהוידע בן איש חי רב פעלים מקבצאל הוא הכה את שני אריאל מואב והוא ירד והכה את הארי בתוך הבור ביום השלג בן איש חי אטו כולי עלמא בני מתי נינהו אלא בן איש חי שאפי' במיתתו קרוי חי רב פעלים מקבצאל שריבה וקבץ פועלים לתורה והוא הכה את שני אריאל מואב שלא הניח כמותו לא במקדש ראשון ולא במקדש שני והוא ירד והכה את הארי בתוך הבור ביום השלג איכא דאמרי דתבר גזיזי דברדא ונחת וטבל איכא דאמרי דתנא סיפרא דבי רב ביומא דסיתוא. והמתים אינם יודעים מאומה אלו רשעים שבחייהן קרויין מתים שנאמר (יחזקאל כא, ל) ואתה חלל רשע נשיא ישראל ואי בעית אימא מהכא (דברים יז, ו) על פי שנים עדים או (על פי) שלשה עדים יומת המת חי הוא אלא המת מעיקרא:
Rabbi Yonatan said to him: Do the dead know so much? Isn’t it stated: “And the dead know nothing” (Ecclesiastes 9:5)? Rabbi Ḥiyya said to him: If you read the verse, you did not read it a second time, and if you read it a second time, you did not read it a third time, and if you read it a third time, they did not explain it to you properly. The meaning of the verse: “For the living know that they will die, and the dead know nothing and have no more reward, for their memory has been forgotten” (Ecclesiastes 9:5): For the living know that they will die, these are the righteous, who even in their death are called living. An allusion to this is as it is stated: “And Benayahu, son of Yehoyada, son of a valiant man of Kabze’el, who had done mighty deeds, he smote the two altar-hearths of Moab; he went down also and slew a lion in the midst of a pit in time of snow” (II Samuel 23:20). He was referred to in the verse as son of a living man. The Gemara wonders: Is that to say, the fact that the Bible referred to him with that appellation, that all others are children of the dead? Rather, the verse should be explained as follows: The son of a living man who lives forever, who even in death is referred to as living. Man of Kabze’el who had done mighty deeds, as he accumulated and gathered many workers for the sake of the Torah. Who killed the two lion-hearted men [Ariel] of Moab, as after his death he left no one his equal, in either the First Temple or the Second Temple periods, as the Temple is called Ariel (see Isaiah 29:1), and the two Ariel refers to the two Temples. In contrast to the righteous, who are referred to as living even after their death, the verse states explicitly: “The dead know nothing.” These are the wicked, who even during their lives are called dead, as the prophet Ezekiel said in reference to a king of Israel who was alive: “And you are a slain, wicked prince of Israel” (Ezekiel 21:30). And if you wish, say instead that the proof is from here: “At the mouth of two witnesses or three witnesses the dead shall be put to death” (Deuteronomy 17:6). This is puzzling. As long as the accused has not been sentenced to death, he is alive. Rather, this person who is wicked is considered dead from the outset.
Also (a bit later in the Sugya)
ת"ש דזעירי הוה מפקיד זוזי גבי אושפזיכתיה עד דאתי ואזיל לבי רב שכיבה אזל בתרה לחצר מות אמר לה זוזי היכא אמרה ליה זיל שקלינהו מתותי בצנורא דדשא בדוך פלן ואימא לה לאימא תשדר לי מסרקאי וגובתאי דכוחלא בהדי פלניתא דאתיא למחר אלמא ידעי
With regard to the deceased’s knowledge of what transpires, come and hear a proof, as it is told: Ze’iri would deposit his dinars with his innkeeper. While he was going and coming to and from the school of Rav, she died, and he did not know where she had put the money. So he went after her to her grave in the cemetery and said to her: Where are the dinars? She replied: Go and get them from beneath the hinge of the door in such and such a place, and tell my mother that she should send me my comb and a tube of eyeshadow with such and such a woman who will die and come here tomorrow. Apparently, the dead know what transpires in this world.
ת"ש דאבוה דשמואל הוו קא מפקדי גביה זוזי דיתמי כי נח נפשיה לא הוה שמואל גביה הוו קא קרו ליה בר אכיל זוזי דיתמי אזל אבתריה לחצר מות ... אדהכי והכי אתא אבוה חזייה דהוה קא בכי ואחיך אמר ליה מאי טעמא קא בכית אמר ליה דלעגל קא אתית מאי טעמא אחיכת דחשיבת בהאי עלמא טובא אמר ליה אי חשיבנא נעיילוה ללוי ועיילוהו ללוי אמר ליה זוזי דיתמי היכא אמר ליה זיל שקלינהו באמתא דרחיא עילאי ותתאי דידן ומיצעי דיתמי
The Gemara cites another proof: Come and hear, as it is told: They would deposit the money of orphans with Shmuel’s father for safekeeping. When Shmuel’s father died, Shmuel was not with him, and did not learn from him the location of the money. Since he did not return it, Shmuel was called: Son of him who consumes the money of orphans. Shmuel went after his father to the cemetery and said to the dead: ... Meanwhile, Shmuel’s father came and Shmuel saw that he was crying and laughing. Shmuel said to his father: Why are you crying? His father replied: Because you will come here soon. Shmuel continued and asked: Why are you laughing? His father replied: Because you are extremely important in this world. Shmuel said to him: If I am important, then let them grant Levi entry to the yeshiva. And so it was that they granted Levi entry to the yeshiva. Shmuel said to his father: Where is the orphans’ money? He said to him: Go and retrieve it from the millhouse, where you will find the uppermost and the lowermost money is ours, and the money in the middle belongs to the orphans. Shmuel said to him: Why did you do that? He replied: If thieves stole, they would steal from our money on top, which the thief would see first. If the earth swallowed up any of it, it would swallow from our money, on the bottom. Apparently, the dead, in this case Shmuel’s father, know when others will die.
The Minchas Elazar wrote that these Gemaras are practical Halacha.