All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger. We ask Allaah to exalt his mention as well as that of his family and all his companions.
There is no doubt that Allaah informed His Prophet about some matters of the unseen, and Allaah has stated in the Quran that it is He Alone Who knows the unseen and that He reveals some of it [but not all of it] to whom He wills of His Prophets, may Allaah exalt their mention. Allaah says (which means): {He Alone is the All-Knower of the unseen and he does not disclose His [knowledge of the] unseen to anyone except whom He has approved of Messengers. Indeed, He sends before him [i.e. each Messenger] and behind him observers.}[Quran 72:26-27]. Allaah further says (which means): {…and they encompass not a thing of His knowledge except for what He wills.}[Quran 2:255]. Therefore, the Prophet did not know anything from the unseen except that which Allaah informed him about. Hence, whoever claims that the Prophet knew all the unseen and knew all that is in the Heavens and the Earth, is indeed a liar and it is feared that he goes out of the fold of Islam by saying such a statement, as by saying so, he contradicts the texts of the Quran. Indeed, Allaah ordered His Prophet to say (which means): {Say [O Muhammad ], "I do not tell you that with me are the Treasures of Allaah nor that I know the unseen, nor do I tell you that I am an angel.}[Quran 6:50]. Allaah further says (which means): {Say [O Muhammad ]: "I hold not for myself [the power of] benefit or harm, except what Allaah has willed. And if I knew the unseen, I could have acquired much wealth.}[Quran 7:188]. In another verse Allaah says (which means): {Say [O Muhammad ]: "I am not something original among the messengers, nor do I know what will be done with me or with you. I only follow that which is revealed to me, and I am not but a clear warner.}[Quran 46:9]. There are many other verses which state that the Prophet did not know the unseen and did not know what would be done to him or to his nation except that which Allaah informed him about, like the narration which is mentioned in the question: "The deeds of my entire nation were exposed to me…" [Muslim] The scholars said that it is probable that the Prophet said this narration when he was lifted to the heavens on the night of Israa', and also the narration: "I see you behind my back." [Al-Bukhari and Muslim] Imaam As-Suyooti said: 'This sight is a real perception peculiar to the Prophet .' However, concluding from these narrations that the Prophet knew the absolute unseen is not correct as we have previously stated. What is worse and more aberrant than this is to conclude that the pious people know the unseen as the ignorant Sufis claim. These people have indeed contradicted the clear texts of the Quran as Allaah says (which means): {Say [O Muhammad ]: "None in the heavens and the Earth knows the unseen except Allaah."}[Quran 27:65]. Moreover, the Sufis are wrong as well in paralleling the pious people to the Prophet who was supported by miracles.
Allaah knows best.