Infallibility may be examined from 3 different angles:
1 – Infallibility in conveying the message
The Prophets were infallible in conveying the message from Allaah
In the Quran:
يا أيها الرسول بلغ ما أنزل إليك من ربك وإن لم تفعل فما بلغت رسالته والله يعصمك من الناس إن الله لا يهدي القوم الكافرين
O Messenger, announce that which has been revealed to you from your Lord, and if you do not, then you have not conveyed His message. And Allah will protect you from the people. Indeed, Allah does not guide the disbelieving people.
ثم لقطعنا منه الوتين
Then We would have cut from him the aorta.
فما منكم من أحد عنه حاجزين
And there is no one of you who could prevent [Us] from him.
وما هو على الغيب بضنين
And Muhammad is not a withholder of [knowledge of] the unseen.
Shaykh ‘Abd al-‘Azeez ibn Baaz (may Allaah have mercy on him) said in Fataawa Ibn Baaz, 6/371:
All the Muslims are unanimously agreed that the Prophets (peace be upon them) – especially Muhammad (peace and blessings of Allaah be upon him) – are infallible and protected from error in that which they conveyed from Allaah. Allaah says
2 – Infallibility from human error
A-They do not commit major sins
B-Matters that have nothing to do with conveying the message and the revelation
As for A:
Shaykh al-Islam Ibn Taymiyah summed it up:
The view that the Prophets are infallible and protected against committing major sins, as opposed to minor sins, is the view of the majority of Muslim scholars and of all groups. It is also the view of the scholars of tafseer and hadeeth and fuqaha’. Indeed, nothing has been narrated from any of the salaf, imams, companions,those who met the compnaions and didn't meet the porphet(PBUH), and those who followed them except that which is in accordance with this view.
Majmoo’ al-Fataawa, 4/319:
As for B:
Majority of scholars are of the view that they are not infallible when it comes to minor sins However, they hastened to repent therefrom if they did such a thing
From the Quran:
فأكلا منها فبدت لهما سوآتهما وطفقا يخصفان عليهما من ورق الجنة وعصى آدم ربه فغوى
And Adam and his wife ate of it, and their private parts became apparent to them, and they began to fasten over themselves from the leaves of Paradise. And Adam disobeyed his Lord and erred.
ثم اجتباه ربه فتاب عليه وهدى
Then his Lord chose him and turned to him in forgiveness and guided [him].
إن هذا أخي له تسع وتسعون نعجة ولي نعجة واحدة فقال أكفلنيها وعزني في الخطاب
Indeed this, my brother, has ninety-nine ewes, and I have one ewe; so he said, 'Entrust her to me,' and he overpowered me in speech."
قال لقد ظلمك بسؤال نعجتك إلى نعاجه وإن كثيرا من الخلطاء ليبغي بعضهم على بعض إلا الذين آمنوا وعملوا الصالحات وقليل ما هم وظن داوود أنما فتناه فاستغفر ربه وخر راكعا وأناب
[David] said, "He has certainly wronged you in demanding your ewe [in addition] to his ewes. And indeed, many associates oppress one another, except for those who believe and do righteous deeds - and few are they." And David became certain that We had tried him, and he asked forgiveness of his Lord and fell down bowing [in prostration] and turned in repentance [to Allah ].
ودخل المدينة على حين غفلة من أهلها فوجد فيها رجلين يقتتلان هذا من شيعته وهذا من عدوه فاستغاثه الذي من شيعته على الذي من عدوه فوكزه موسى فقضى عليه قال هذا من عمل الشيطان إنه عدو مضل مبين
And he entered the city at a time of inattention by its people and found therein two men fighting: one from his faction and one from among his enemy. And the one from his faction called for help to him against the one from his enemy, so Moses struck him and [unintentionally] killed him. [Moses] said, "This is from the work of Satan. Indeed, he is a manifest, misleading enemy."
قال رب إني ظلمت نفسي فاغفر لي فغفر له إنه هو الغفور الرحيم
He said, "My Lord, indeed I have wronged myself, so forgive me," and He forgave him. Indeed, He is the Forgiving, the Merciful.
Prophet Mohamed PBUH :
ا أيها النبي لم تحرم ما أحل الله لك تبتغي مرضات أزواجك والله غفور رحيم
O Prophet, why do you prohibit [yourself from] what Allah has made lawful for you, seeking the approval of your wives? And Allah is Forgiving and Merciful.
From the Hadith:
Muslim narrated in his Saheeh (4588) that Ibn ‘Abbaas said:
When the prisoners were taken captive, the Messenger of Allaah (S) (PBUH) said to Abu Bakr and ‘Umar: "What do you think about these prisoners?" Abu Bakr said: "O Prophet of Allaah, they are our cousins and kinsmen. I think that we should accept a ransom from them which will give us some support against the kuffaar, and perhaps Allaah will guide them to Islam." The Messenger of Allaah (PBUH) said: “What do you think, O Ibn al-Khattaab?” He said: "I say, no, by Allaah, O Messenger of Allaah. I do not agree with Abu Bakr. I think that you should hand them over to us so that we may strike their necks (execute them). Hand over Aqeel to ‘Ali so that he may strike his neck, and hand over So and so – a relative of Umar – to me, for these are the leaders and veterans of kufr." The Messenger of Allaah (peace and blessings of Allaah be upon him) liked what Abu Bakr said and he did not like what I [‘Umar] said. The next day I came and found the Messenger of Allaah (PBUH) and Abu Bakr weeping. I said: "O Messenger of Allaah, tell me, what has made you and your companion weep? If there is a reason to weep, I will weep with you, and there is no reason, I will pretend to weep in sympathy with you because you are weeping." The Messenger of Allaah (PBUH) said: "I am weeping because I was shown the torture to which they were subjected. It was brought as close to me as this tree" – a tree which was near the Prophet of Allaah (peace and blessings of Allaah be upon him) – then Allaah revealed the words (interpretation of the meaning):
ا كان لنبيّ أن يكون له أسرى حتى يثخن في الأرض تريدون عرض الدنيا والله يريد الآخرة والله عزيز حكيم
It is not for a prophet to have captives [of war] until he inflicts a massacre [upon Allah 's enemies] in the land. Some Muslims desire the commodities of this world, but Allah desires [for you] the Hereafter. And Allah is Exalted in Might and Wise.
لولا كتاب من الله سبق لمسكم فيما أخذتم عذاب عظيم
If not for a decree from Allah that preceded, you would have been touched for what you took by a great punishment.
فكلوا مما غنمتم حلالا طيبا واتقوا الله إن الله غفور رحيم
So consume what you have taken of war booty [as being] lawful and good, and fear Allah . Indeed, Allah is Forgiving and Merciful.
Shaykh al-Islam Ibn Taymiyah said:
What has been narrated from the majority of scholars is that they (the Prophets) are not infallible with regard to minor sins, but they are not left to persist therein. They do not say that this does not happen under any circumstances. The first group from whom it was narrated that they are infallible in all cases, and who say that the most, are the Shiite, who say that they are infallible and protected even against forgetfulness and misunderstanding.
Majmoo’ al-Fataawa, 4/320
3- Unintentional mistakes with regard to some worldly matters
With regard to mistakes in some worldly matters, it is permissible for them to make such mistakes although their reason is sound and their insight is strong. This happened to several of the Prophets including our Prophet Muhammad (peace and blessings of Allaah be upon him). This happened with regard to various spheres of life such as medicine, agriculture, etc.
This happened to several of the Prophets including our Prophet Muhammad (peace and blessings of Allaah be upon him).
Muslim narrated in his Saheeh (6127) that Raafi’ ibn Khadeej said:
The Prophet of Allaah (PBUH) came to Madeenah and found them pollinating the palm trees. He said: "What are you doing?" They said: "We always do this." He said: "Perhaps if you do not do it, that will be better." So they did not do it, and the harvest failed. They told him about that and he said: "I am only human. If I tell you to do something with regard to your religion, then do it, but if I tell you to do something based on my own opinion, then I am only human."
Hence it is known that the Prophets are infallible and protected from error with regard to the Revelation, so we should beware of those who cast aspersions upon the Messenger’s conveying of the Message and his laws, and say that it is his own personal opinion. The Prophet (peace and blessings of Allaah be upon him) could never do such a thing. Allah says:
وما ينطق عن الهوى
Nor does he speak from [his own] inclination.
إن هو إلا وحي يوحى
It is not but a revelation revealed,
The Standing Committee was asked:
Do the Prophets and Messengers make mistakes? They replied:
Yes, they make mistakes but Allaah does not let them persist in their mistakes, rather he points out their mistakes to them as a mercy to them and their nations, and He forgives them for their mistakes, and accepts their repentance by His Grace and Mercy, for Allaah is Oft-Forgiving, Most Merciful, as will be clear to anyone who studies the verses of the Qur’aan which speak of that.
Fataawa al-Lajnah al-Daa’imah, 3/194