In the Name of Allaah, the Most Merciful, the Al–Merciful…
[Our shaykh, the great scholar of Islaam, Shaykh Muhammad ibn Saalih al-‘Uthaymeen (may Allaah have Mercy on him), posed an important question that many Muslims debate about, and answered it with sound evidence, showing the weakness of the stance of those who would disagree, saying…]
Could human errors ( الخطأ ) have occurred from the Prophet (may Allaah raise his rank and grant him peace)?
The answer: The Prophet (may Allaah raise his rank and grant him peace) said:
(( اللهم اغسلني من خطاياي ))
(( O Allaah! Cleanse me of my mistakes… )) 
So he directly ascribed “mistakes” ( خطايا ) to himself. He also used to say:
(( اللهم اغفر لي ذنبي كله دقه وجله وأوله وآخره وعلانيته وسره ))
(( O Allaah! Forgive me for all of my sins, the small and large of them, the first and last of them, the open and the secret of them. )) 
And Allaah, the Most High, has said:
( واستغفر لذنبك وللمؤمنين والمؤمنات )
( And ask (O Muhammad) for forgiveness for your sins, and for the believing men and women. ) 
And Allaah has said:
( ليغفر لك الله ما تقدم من ذنبك وما تأخر )
( So that Allaah would forgive for you your past and future sins ) 
But here is the real question: Could these “sins” ( ذنوب ) remain (within his actions) or not?
The answer: No, because the Prophet (may Allaah raise his rank and grant him peace) was protected (by Allaah) from continuing in any sin, and he was forgiven for it, unlike others who sin and persist in it and continue on in his act of disobedience, and thus perhaps may not be forgiven.
As for the Prophet (may Allaah raise his rank and grant him peace), then he would always be alerted to it (the sin or mistake), no matter what it was.
( يا أيها النبي لم تحرم ما أحل الله لك تبتغي مرضات أزواجك والله غفور رحيم )
(O Prophet! Why do you abstain from something Allaah has made permissible for you, seeking to please your wives? And Allaah is Oft-Forgiving, Most Merciful. ) 
This is the key to understanding this issue that the people dispute over!
However, there was a kind of sin that – no doubt – the Prophet (may Allaah raise his rank and grant him peace) was protected from: lying and betrayal. If he could have done that, then his message could have been corrupted, may Allaah raise his rank and grant him peace. Therefore such behavior was not possible for him.
He was likewise protected from anything that would take away from the completeness of his basic worship or manners, like shirk (polytheism) or bad behavior like fornication and similar things.
However, it is possible that mistakes occurred between him and his Lord (alone), however they were small and forgiven, since Allaah has forgiven all his sins, those from the earlier part of his life, as well as those from the later part.
I say this because some of the scholars – may Allaah have Mercy on them – – said,“Whenever the Prophet (may Allaah raise his rank and grant him peace) ascribed a sin to himself, the intention was: the sins of his followers, not his own, since he did not sin. So every sin he ascribed to himself was intended to be the sins of his followers.”
No doubt, this position has a level of academic weakness in it, since Allaah has said:
( واستغفر لذنبك وللمؤمنين )
( And ask (O Muhammad) for forgiveness for your sins, and for the believers. ) 
Using the word “and” here indicates a difference between what is before and after it. 
There is nothing negative in this against the Messenger (may Allaah raise his rank and grant him peace) in any way, in saying that had some small sins. He never persisted in them, and further, he was forgive for them.
How often does one of us become better after a sin than he was before! A person often commits an error and falls into sin, and thereafter finds his heart extremely saddened, and so he turns to Allaah, repenting to Him much, to the point that he keeps thinking about the sin, full of remorse, repenting continually.
On the other hand, a person could consider himself obedient, from the people of devout obedience (to Allaah), and yet he is overcome by self-amazement and self-admiration, not repenting to Allaah in a way that corrupts his (practice of the) Religion!
Allaah is All-Wise, He tests people with disobedience at times to improve their condition, like when a He puts a person through the trial of hunger (for a time) to improve his physical well-being. Hadn’t Allaah chosen Adam only after disobedience and repentance?! As He has said:
( ثم اجتباه ربه )
( …And then His Lord chose him… ) 
Meaning: After he sinned and repented, His Lord then chose him, accepted his repentance, and guided him.
As well, look to those who stayed behind from the Battle of Tabook , what happened to them?! No doubt, they achieved a level of eemaan and a higher station they had not enjoyed previously! Could (Quranic) Verses about them (specifically) have been revealed and then recited until the Day of Judgment had they not fallen into that and then repented to Allaah?!
In summary, the most important thing to understand here is that no people are protected from error (absolutely), however the Prophets (may Allaah raise their rank and grant them peace) were protected from the things mentioned, and they were protected from persisting in small sins as well, as they would always repent from them. 
Source: Ash-Sharh al-Mumti’ (3/50-52), the shaykh’s explanation to Zaad al-Mustaqni, translated by Moosaa Richardson.
FOOTNOTES (from the translator):
 From an authentic hadeeth collected by Al-Bukhaaree (744) and Muslim (598), on the authority of Aboo Hurayrah (may Allaah be pleased with him).
 From an authentic hadeeth collected by Muslim (483), on the authority of Aboo Hurayrah (may Allaah be pleased with him).
 Soorah Muhammad (47:19) and a translation of its meaning
 Soorah al-Fat-h (48:2) and a translation of its meaning
 Soorah at-Tahreem (66:1) and a translation of its meaning
 Meaning: The basic meaning of the “waaw” in Arabic is like the word “and”, which most commonly refers to another seperate thing, not the same thing itself. There are exceptions, but this is the basic rule in both English and Arabic.
 Soorah Taa-Haa (20:122) and a translation of its meaning
 The story of Ka’b ibn Maalik, and his two companions (Muraarah ibn ar-Rabee’ and Hilaal ibn Umayyah) who remained behind during the Battle of Tabook is found in al-Bukhaaree and Muslim. Review the hadeeth in the beautiful chapter about repentance in the book, Riyaadh as-Saaliheen by an-Nawawee (hadeeth #22).
 This argument could be further strengthened by other clear evidences as well. For example, the generality of the hadeeth:
(( كل بني آدم خطاء وخير الخطائين التوابون ))
(( Every single son of Adam continually errs (sins), while the best of those who continually err are those who continually repent. ))
This hadeeth was collected by Ibn Maajah (4251) and declared hasan (authentic) by al-Albaanee. We would need a clear evidence to exempt our Messenger from this broad generality (may Allaah raise his rank and grant him peace).
Furthermore, the Messenger of Allaah (may Allaah raise his rank and grant him peace) used to stand for long hours of prayer in the night, until his feet would swell and crack. When ‘Aa’ishah (may Allaah be pleased with her) noticed this, she remarked, “Why do you do this when Allaah has forgiven your past and future sins?!”
The hadeeth was collected by al-Bukhaaree (4837) and Muslim (2819). The point is that ‘Aa’ishah (may Allaah be pleased with her) would likely not have asked this question if she had thought “his sins” really meant the sins of his followers, not his own personal sins, and Allaah knows best.