Reconciling between the verse “We shall make you to recite (the Quran), so you (O Muhammad shall not forget (it)” and the fact that the Prophet sometimes forgot when praying and otherwise
Question

Allah, may He be glorified and exalted, says that the Messenger of Allah (blessings and peace of Allah be upon him) will not forget anything of the Quran:
“We shall make you to recite (the Quran), so you (O Muhammad (blessings and peace of Allah be upon him)) shall not forget (it),
Except what Allah, may will, He knows what is apparent and what is hidden”
[al-A‘la 87:6-7].
This is the belief of Ahl as-Sunnah wa’l-Jamaa‘ah, but how can we reconcile between this verse and the hadith which says “May Allah have mercy on him, for he has reminded me of such and such, a verse that I had missed in soorah such and such.” (Agreed upon)
Praise be to Allah.Firstly:
Allah, may He be exalted, says (interpretation of the meaning):
“We shall make you to recite (the Quran), so you (O Muhammad (blessings and peace of Allah be upon him)) shall not forget (it),
Except what Allah may will, He knows what is apparent and what is hidden”
[al-A‘la 87:6-7].
Here Allah, may He be exalted, says to His Prophet (blessings and peace of Allah be upon him) that He will teach him this Quran and cause him to memorise it so that he will not forget anything of it, except what Allah causes to be taken away and abrogated.
Ibn Jaziy (may Allah have mercy on him) said:
This is addressed to the Prophet (blessings and peace of Allah be upon him); Allah promised him that He would make him recite the Quran so that he would not forget it. This is a miracle that was bestowed upon him (blessings and peace of Allah be upon him), as he was unlettered and could not write, yet despite that he did not forget what Jibreel (peace be upon him) recited to him of the Quran. It was also said that the meaning of the verse is similar to the verse in which Allah says (interpretation of the meaning): “Move not your tongue concerning (the Qu’ran, O Muhammad (blessings and peace of Allah be upon him)) to make haste therewith” [al-Qiyaamah 75:16]. The Prophet (blessings and peace of Allah be upon him) used to move his tongue as Jibreel recited it, for fear of forgetting it, so Allah guaranteed to him that he would not forget it. It was also said that the words “so you will not forget it” was a an command not to forget it, for Allah knew that not forgetting is not possible for human beings, and what was meant was a command to him to pay attention to it that he would not forget it – but this is far-fetched.
End quote from at-Tas-heel (p. 2597)
As-Sa‘di (may Allah have mercy on him) said:
That is, We will preserve what We have revealed to you of the Book, and We will instil it in your heart, so that you will forget nothing of it.
This was great glad tidings from Allah to His slave and Messenger Muhammad (blessings and peace of Allah be upon him), that Allah would teach him knowledge that he would not forget, “Except what Allah may will”, of what His wisdom may dictate that He should cause you to forget for a significant reason.
End quote from Tafseer as-Sa‘di (p. 920)
This is the forgetting from which the Prophet (blessings and peace of Allah be upon him) was protected, which is forgetting what he had been commanded to convey. This is what he would remember and not forget, until the religion was completed and the blessing was perfected.
Secondly:
with regard to the report narrated by al-Bukhaari (5038) and Muslim (788) from ‘Aa’ishah, who said: The Messenger of Allah (blessings and peace of Allah be upon him) heard a man reciting at night and he said: “May Allah have mercy on him, for he has reminded me of such and such, a verse that I had been caused to forget in soorah such and such”,
This refers to the normal, natural kind of forgetting with which Adam (peace be upon him) and his offspring were created. That happened to the Prophet (blessings and peace of Allah be upon him) sometimes, and it is not what is referred to in the verse (interpretation of the meaning): “We shall make you to recite (the Quran), so you (O Muhammad (blessings and peace of Allah be upon him)) shall not forget (it)” [al-A‘la 87:6].
An-Nawawi (may Allah have mercy on him) said: This indicates that it was possible for the Prophet (blessings and peace of Allah be upon him) to forget some of that which he had already conveyed to the ummah. End quote.
Al-Haafiz Ibn Hajar (may Allah have mercy on him) said:
Al-Ismaa‘eeli said: With regard to the Prophet (blessings and peace of Allah be upon him) forgetting some part of the Quran, that is of two types:
The first is what he might forget and then quickly remember. This is part of human nature, and is referred to in the words of the Prophet (blessings and peace of Allah be upon him) in the hadith of Ibn Mas‘ood about forgetting: “I am only human like you; I forget as you forget.”
The second type is when Allah removed from his heart that which He wanted to abrogate from the Quran. This is referred to as the exception in the verse in which Allah, may He be exalted, says (interpretation of the meaning):
“We shall make you to recite (the Quran), so you (O Muhammad (blessings and peace of Allah be upon him)) shall not forget (it),
Except what Allah may will”
[al-A‘la 87:6-7].
With regard to the first type, it is something temporary and is soon remembered, based on the apparent meaning of the verse in which Allah, may He be exalted, says (interpretation of the meaning): “Verily We: It is We Who have sent down the Dhikr (i.e. the Quran) and surely, We will guard it (from corruption)” [al-Hijr 15:9].
With regard to the second type, it is included in the words of Allah, may He be exalted (interpretation of the meaning): “Whatever a Verse (revelation) do We abrogate or cause to be forgotten” [al-Baqarah 2:106].
End quote.
Ibn Baaz (may Allah have mercy on him) said:
The ummah is agreed that the Messengers were infallible in their conveying of the message, so they did not forget anything of that which Allah revealed to them, except something that was abrogated, and Allah, may He be glorified and exalted, guaranteed to His Messenger (blessings and peace of Allah be upon him) that He would make him recite it so that he would not forget it, except something that Allah wanted to cause him to forget. He also guaranteed him that He would cause him to memorise the entire Quran. Allah, may He be exalted, says (interpretation of the meaning):
“We shall make you to recite (the Quran), so you (O Muhammad (blessings and peace of Allah be upon him)) shall not forget (it),
Except what Allah may will, He knows what is apparent and what is hidden”
[al-A‘la 87:6-7]
“It is for Us to collect it and to give you (O Muhammad (blessings and peace of Allah be upon him)) the ability to recite it (the Quran),
And when We have recited it to you (O Muhammad (blessings and peace of Allah be upon him) through Jibrael (Gabriel)), then follow you its (the Qurans) recital.”
[al-Qiyaamah 75:16-17].
End quote from Majmoo‘ Fataawa Ibn Baaz (6/371)
The point is that forgetting is of two types: forgetting in the sense of removal, abrogation and loss of the forgotten material altogether, which is what the Prophet (blessings and peace of Allah be upon him) was protected from, so that he did not forget anything of the Quran except what Allah willed that He should cause him to forget, of that which He wanted to remove and abrogate, which is what is referred to in the words(interpretation of the meaning):
“We shall make you to recite (the Quran), so you (O Muhammad (blessings and peace of Allah be upon him)) shall not forget (it),
Except what Allah may will”
[al-A‘la 87:6-7].
This is what Ahl as-Sunnah are unanimously agreed did not happen to the Prophet (blessings and peace of Allah be upon him).
The second type is the kind of forgetting that is part of human nature. This did happen to the Prophet (blessings and peace of Allah be upon him) on occasion, and this is what he referred to when he said: “I am only human like you; I forget as you forget. If I forget, then remind me.” Narrated by al-Bukhaari (386) and Muslim (889). And he also said:  “May Allah have mercy on him, for he has reminded me of such and such, a verse that I had been caused to forget in soorah such and such.” There is nothing problematic in this, because it did not affect the obligation to convey the message, so long as the verse or the thing that had been forgotten was preserved, and the Prophet (blessings and peace of Allah be upon him) would remember it soon after that. Hence he  (blessings and peace of Allah be upon him) remembered it himself, as we see in the hadith mentioned, that he forgot something whilst he was praying and no one reminded him of it.
Please see also the answer is to questions no. 42216 .
And Allah knows best.