Praise be to Allah.
Firstly:
One of the Muslims’ beliefs is the belief that Allah alone is the Knower of the unseen, and no one knows the unseen except Him. Allah, may He be glorified, says (interpretation of the meaning):
“Say: ‘None in the heavens and the earth knows the Ghaib (unseen) except Allah, nor can they perceive when they shall be resurrected.’”
[an-Naml 27:65].
Ibn Katheer (may Allah have mercy on him) said:
Here Allah, may He be exalted, instructs His Messenger (blessings and peace of Allah be upon him) to say to all of creation, informing them that no one knows the unseen except Allah, may He be glorified and exalted, for He is the only one who has this knowledge, with no partner or associate.
End quote from Tafseer Ibn Katheer (6/207)
But Allah ,may He be exalted, may inform whomever He wills of His Messengers of whatever He wills of the unseen. Allah, may He be exalted, says (interpretation of the meaning):
“(He Alone) the All-Knower of the Ghaib (unseen), and He reveals to none His Ghaib (unseen).
Except to a Messenger (from mankind) whom He has chosen (He informs him of unseen as much as He likes), and then He makes a band of watching guards (angels) to march before him and behind him”
[al-Jinn 72:26-27].
The scholars of the Standing Committee said:
The basic principle regarding matters of the unseen is that they are known only to Allah, but Allah, may He be exalted, may disclose matters of the unseen to whomever He wills among His Messengers. Allah, may He be exalted, says (interpretation of the meaning):
“(He Alone) the All-Knower of the Ghaib (unseen), and He reveals to none His Ghaib (unseen).
Except to a Messenger (from mankind) whom He has chosen (He informs him of unseen as much as He likes), and then He makes a band of watching guards (angels) to march before him and behind him”
[al-Jinn 72:26-27].
End quote from Fataawaa al-Lajnah ad-Daa’imah (1/122-123)
That which is disclosed to the Messenger of matters of the unseen is only through revelation from Allah, may He be exalted. Hence Allah, may He be glorified and exalted, says (interpretation of the meaning):
“Say (O Muhammad blessings and peace of Allah be upon him): ‘I don’t tell you that with me are the treasures of Allah, nor (that) I know the unseen; nor I tell you that I am an angel. I but follow what is revealed to me by inspiration.’”
[al-An‘aam 6:50].
The scholars of the Standing Committee said:
Knowledge of the unseen is something that is unique to Allah, may He be exalted, so none of His creation, jinn or others, knows that except what Allah may reveal to whomever He wills among His angels or Messengers.
End quote from Fataawa al-Lajnah ad-Daa’imah (1/346)
The Prophet (blessings and peace of Allah be upon him) did not have knowledge of the unseen, as is the apparent meaning of the verse in which Allah, may He be exalted, says (interpretation of the meaning):
“Say (O Muhammad blessings and peace of Allah be upon him): "I don’t tell you that with me are the treasures of Allah, nor (that) I know the unseen”
[al-An‘aam 6:50].
But Allah is the Knower of the unseen, some of which which He discloses to whomever He wills, as He says (interpretation of the meaning):
“(He Alone) the All-Knower of the Ghaib (unseen), and He reveals to none His Ghaib (unseen)”
[al-Jinn 72:26].
Al-Qutubi (may Allah have mercy on him) said:
The scholars (may Allah have mercy on them) said: as Allah, may He be glorified, is praised for having knowledge of the unseen, which He has kept to Himself, to the exclusion of His creation, this indicates that no one has knowledge of the unseen except Him. Then He made an exception for those with whom He is pleased of the Messengers, and disclosed to them whatever He willed of the unseen, by means of revelation to them, which He made a miracle for them and a true sign of their Prophethood.
End quote from Tafseer al-Qurtubi (1 9/28)
See also the answer to question no. 101968
Secondly:
Al-Bukhaari (418) and Muslim (424) narrated from Abu Hurayrah that the Messenger of Allah (blessings and peace of Allah be upon him) said:
“Do you think that I face the qiblah (and do not know what you are doing)? By Allah, your bowing and prostrating are not hidden from me; I can see you behind my back.”
An-Nawawi (may Allah have mercy on him) said: The scholars said: What this means is that Allah, may He be exalted, created for the Prophet (blessings and peace of Allah be upon him) the ability in the back of his head to see what was behind him, and he (blessings and peace of Allah be upon him) was granted more extraordinary abilities than this. This is not contrary to reason or textual evidence; rather the texts confirm this, so we must believe in it. End quote.
These are miracles and signs with which Allah supported His Prophet (blessings and peace of Allah be upon him) and they were unique to him. Al-Haafiz Ibn Rajab (may Allah have mercy on him) said:
This does not mean that he used to turn around and look behind him whilst he was praying, so that he could see how they were praying, as some people think. Imam Ahmad refuted those who claimed that, and affirmed that this was one of his unique characteristics, and one of his signs and miracles.
End quote from Fath al-Baari by Ibn Rajab (4/341)
Al-Haafiz Ibn Hajar (may Allah have mercy on him) said:
The correct view is that it is to be interpreted as it appears to mean, and that this “seeing” was in a real and literal sense that was unique to the Prophet (blessings and peace of Allah be upon him) and was an extraordinary feat. Based on that, the author narrated this hadeeth under the heading of the signs of Prophethood; it was also narrated under a similar heading from Imam Ahmad and others.
End quote.
To sum up:
This was one of the unique characteristics and miracles of the Messenger of Allah (blessings and peace of Allah be upon him), but this does not contradict what we stated above about Allah being the only One who has knowledge of the unseen, because we have affirmed that Allah may disclose to whomever He wills among His Messengers whatever He wills of matters of the unseen. Hence the Messenger knew some matters of the unseen of which his Lord, may He be glorified, informed him. But what is mentioned in this hadeeth has nothing to do with matters of the unseen. The Messenger of Allah (blessings and peace of Allah be upon him) did not say to his Companions “I know what is unseen behind my back” or “I know such and such”. Rather what the Messenger of Allah (blessings and peace of Allah be upon him) knew in this case was something visible and seen. The only matter of note in this case is that ordinarily a person only sees what is in front of him, but the Messenger (blessings and peace of Allah be upon him) in this instance blessings and peace of Allah be upon him what was behind him. So it was an extraordinary event, and his seeing what was behind his back is confirmed even though it was something out of the ordinary.
And Allah knows best.
Comment