The kashf (intuition, insight, finding out about things that are unseen) that may happen to a person is of several kinds. One type is psychological, which both Muslims and kaafirs have in common. Another kind is spiritual, which comes via revelation. A third type is satanic, which comes via the jinn.
Shaykh al-Islam Ibn Taymiyah said:
We do not deny that people may experience some kind of kashf, whether when awake or in their dreams when the soul is less connected to the body, either by means of spiritual practices or otherwise. This is the psychological kashf which is the first type of kashf.
But it is also proven through rational evidence as well as shar’i evidence that the jinn exist and that they tell people things about the unseen, as happens in the case of soothsayers, those who are possessed and the like.
The second type is that which is done by outside forces, such as the jinn who tell the soothsayers many things. This is something that is well known, especially to those who have experienced it, and we have come to know about these things on many occasions. This is a type of kashf that has nothing to do with the first type, and this is the second type of kashf.
With regard to the third type, it is what is conveyed by the angels and this is the noblest type, as is indicated by the texts and by rational evidence. Information about the unseen may come from psychological sources, or from evil sources, whether they are satanic or not, or it may come from angelic sources.
Al-Safadiyyah, p. 187-189
Ibn al-Qayyim said:
Partial kashf is something which both believers and kaafirs, righteous and immoral, may share, such as knowing what is in a person’s house or what is in his hand or under his garment, or whether his wife is pregnant with a boy or girl after the gender has been determined, or things that cannot be seen such as things that are taking place far away, and so on. This may come from the Shaytaan sometimes and from one's own self sometimes, hence it may happen to the kuffaar such as the Christians and people who worship fire or the cross. Ibn Sayyaad told by means of kashf the Prophet (peace and blessings of Allaah be upon him) what he was hiding for him. The Messenger of Allaah (peace and blessings of Allaah be upon him) said to him, “You are from among the brethren of the soothsayers.” He told him that his kashf was like the kashf of the soothsayers. Similarly the liar Musaylimah, even though he was a kaafir of the worst type, could tell his companions of what one of them had done in his house and what he had said to his wife, because his shaytaan told him that so that he could mislead the people. The same was true of al-Aswad al-‘Anasi and al-Haarith al-Mutanabbi al-Dimashqi, who emerged at the time of ‘Abd al-Malik ibn Marwaan, and others of their ilk, whose numbers are known only to Allaah. We ourselves and others have seen a group of them and people have witnessed the kashf of monks who worship the cross, as is well known.
Spiritual kashf of this type is like the kashf of Abu Bakr when he told ‘Aa’ishah that his wife was pregnant with a girl; and the kashf of ‘Umar (may Allaah be pleased with him) when he said, “O Saariyah, the mountain!” – i.e., stay close to the mountain. There are many such instances among the close friends (awliya’) of Allaah.
Madaarij al-Saalikeen, 3/227, 228
What happened to ‘Umar ibn al-Khattaab (may Allaah be pleased with him) is saheeh and is well proven. Naafi’ said that ‘Umar sent out a military detachment and he appointed a man called Saariyah in charge of them. Whilst ‘Umar was delivering the khutbah one Friday, he said, “O Saariyah, the mountain! O Saariyah, the mountain!” And they found out that Saariyah had moved towards the mountain at that moment on the Friday even though there was the distance of a month’s journey between them.
Narrated by Ahmad in Fadaa’il al-Sahaabah, 1/269; classed as saheeh by al-Albaani in al-Silsilah al-Saheehah, 1110
This was a miracle (karaamah) bestowed upon ‘Umar (may Allaah be pleased with him); either it happened by means of inspiration and his voice reached Saariyah – as is the view of Ibn al-Qayyim – or it happened by means of psychological kashf and his voice reached Saariyah – which is what we will see below in the words of Shaykh al-Albaani. In either case, it was undoubtedly a miracle (karaamah).
With regard to what happens to the Sufis, it is not spiritual kashf, rather it is either psychological kashf which is something that they have in common with the kuffaar, or it is of satanic origin, which is usually the case.
Spiritual kashf only happens to the close friends (awliya’) of Allaah who establish sharee’ah and venerate it. It is known that the Sufis do not do that. What happened to ‘Umar, although it is correct to describe it as kashf, was spiritual kashf.
Shaykh al-Albaani (may Allaah have mercy on him) said:
There can be no doubt that the call mentioned was inspiration from Allaah to ‘Umar. That is nothing strange, because he was “muhaddath” (inspired) as was narrated from the Prophet (peace and blessings of Allaah be upon him), but that does not mean that ‘Umar was shown the situation of the army or that he saw them with his own eyes. The use of this as evidence by some of the Sufis for the claims that they make about the awliya’ (“saints”) having kashf and that they can see what is in people’s hearts is utter falsehood. How can it be otherwise, when that is one of the unique attributes of the Lord of the Worlds Who alone has knowledge of the unseen and sees what is in people’s hearts?
I wonder, how can they make such a false claim when Allaah says in His Book (interpretation of the meaning):
“(He Alone is) the All‑Knower of the Ghayb (Unseen), and He reveals to none His Ghayb (Unseen).
Do they believe that those awliya’ are Messengers of Allaah so that it may be said of them that they can know the unseen as much as Allaah tells them?! Glory be to You (O Allaah)! This is a great lie (cf. al-Noor 24:16).
This story is saheeh and is proven. It was a miracle (karaamah) with which Allaah honoured ‘Umar, by means of which the Muslim army was saved from capture or destruction. But it does not mean that he had knowledge of the unseen, as the Sufis claim. Rather it was a kind of inspiration, in the sense defined in sharee’ah, or a kind of telepathy, which is not infallible. It may be correct, as in this incident, or it turn out to be wrong, as usually happens to people. Hence every close friend of Allaah (wali) must adhere to sharee’ah in everything that he does or says, lest he do something that goes against sharee’ah and thus lose the status of being a friend of Allaah, which Allaah has described in comprehensive terms when He said (interpretation of the meaning):
“No doubt! Verily, the Awliyaa’ of Allaah, no fear shall come upon them nor shall they grieve.
Those who believed, and used to fear Allaah much (by abstaining from evil deeds and sins and by doing righteous deeds)”
And the poet said:
“If you see a man flying through the air or walking on the water, but he does not adhere to the limits of sharee’ah,
then you should realize that this is a temptation which is leading him astray, and he is a man of bid’ah.”
Al-Silsilah al-Saheehah, 3/102-104
And Allaah knows best.