Praise be to Allaah.
We thank you for sending this question in an effort to find the right answer instead of merely accepting what you have heard from someone who claims to be a Muslim.
The ummah (Muslim nation) is agreed that the Messengers are infallible in carrying out their mission they do not forget anything that Allaah has revealed to them except with regard to matters that have been abrogated. They are also infallible in conveying the Message they do not conceal anything that Allaah has revealed to them, for that would be a betrayal and it is impossible to imagine that they could do such a thing. Allaah says (interpretation of the meaning): O Messenger! Proclaim (the Message) which has been sent down to you from your Lord. And if you do not ,then you have not conveyed His Message [al-Maaidah 5:67]. If anything is concealed or changed, then the punishment of Allaah will befall the one who is guilty of doing these things, as Allaah says (interpretation of the meaning): And if he [Muhammad (peace and blessings of Allaah be upon him)] had forged a false saying concerning Us [Allaah], We surely would have seized him by his right hand (or with power and might), and then certainly should have cut off his life artery (aorta). [al-Haqqah 69:44-46]. One aspect of infallibility is that they (the Prophets) do not forget anything of that which Allaah has revealed to them, and thus no part of the revelation is lost.
[Al-rusul wal-risaalaat (The Messengers and their missions), Omar al-Ashqar, p. 97]
Omar al-Ashqar also said (op. cit., p.102): The Prophets and Messengers may also strive to find the right judgement in the situations with which they are faced, and they judge according to what they themselves see and hear they do not have knowledge of the Unseen. They may make an incorrect judgement, as happened to the Prophet of Allaah Dawood (David), who failed to do so, and Allaah helped his son Sulaymaan (Solomon) to come up with the right answer in that particular case. Abu Hurayrah (may Allaah be pleased with him) reported that he heard the Prophet (peace and blessings of Allaah be upon him) say: There were two women, each of whom had a son. A wolf came and carried off the son of one of them, who said to the other, The wolf has taken your son. The other said, No, he took your son. They came to Dawood to ask him to judge between them, and he ruled in favour of the older woman. Then they went to Sulaymaan the son of Dawood and told him what had happened. He said, Bring a knife and divide the child between them. The younger woman said, Do not do that, may Allaah have mercy on you! He is her son. So Sulaymaan ruled in favour of the younger woman. (Reported by al-Bukhaari).
The Prophet (peace and blessings of Allaah be upon him) explained this story: Umm Salamah, the wife of the Prophet (peace and blessings of Allaah be upon him) narrated that he heard a dispute going on at the door of his apartment, so he went out and told them: I am no more than a human being. Disputing parties may come to me, and one of you may be more eloquent and persuasive than the other, so I may think that he is telling the truth and rule in favour of him. Whoever has a judgement in favour of him to the detriment of a fellow-Muslims rights, this is a piece of the Fire let him take it or leave it.
When it comes to the idea of the Prophets committing major sins (kabaair), Shaykh al-Islam Ibn Taymiyah said (in al-Fataawaa, 4/319): The belief that the Prophets are free of major sins, but not of minor sins, is the opinion of the majority of Islamic scholars and of all (Muslim) groups It is the opinion of most mufassireen (commentators on the Quran), scholars of hadeeth and fuqaha (jurists).
With regard to whether it is possible for the Prophets to commit minor sins, in Lawaami al-Anwaar al-Bahiyyah (2/214), al-Safaareeni quoted from Ibn Hamdaan who said in Nihaayat al-Mubtadieen: They are infallible in conveying the commands and message of Allaah, but they are not infallible in any other regard. They may make mistakes, forget things, or commit minor sins according to the most well-known opinion (of the scholars) but they will not be approved for these mistakes.
The majority of scholars take the following as evidence to support their claim that the Prophets are not free from minor sins:
Adams sin in eating from the tree from which Allaah had forbidden him to eat. Allaah says (interpretation of the meaning): And (remember) when We said to the angels, Prostrate yourselves to Adam. They prostrated (all) except Iblees (Satan), who refused. Then We said, O Adam! Verily, this is an enemy to you and to your wife. So let him not get you both out of Paradise, so that you be distressed in misery. Verily, you have (a promise from Us) that you will never be hungry therein nor naked. And you (will) suffer not from thirst therein nor from the suns heat. Then Shaytaan whispered to him, saying: O Adam! Shall I lead you to the Tree of Eternity and to a kingdom that shall never waste away? Then they both ate of the tree, and so their private parts appeared to them, and they began to stick on themselves leaves from Paradise for their covering. Thus did Adam disobey his Lord, so he went astray. [Ta-Ha 20:116-121]
When Nooh prayed for his kaafir son, Allaah rebuked him for doing so, and taught him that this person was not a member of his family, and that this prayer was not a righteous deed on his part. So Nooh sought forgiveness from his Lord, repented and returned to Allaah: Nooh said: O my Lord! I seek refuge with You from asking You that of which I have no knowledge. And unless You forgive me and have Mercy on me, I would indeed be one of the losers. [Hood 11:47 interpretation of the meaning].
When Dawood realized that he had been too quick to judge, without listening to what the second disputant had to say, he hastened to repent: and he sought Forgiveness of his Lord, and he fell down prostrate and turned (to Allaah) in repentance. [Saad 38:24 interpretation of the meaning].
Everyone, even the Prophets, is in need of the forgiveness of Allaah. Allaah has blessed His Prophets by forgiving their sins, and He has blessed our Prophet (peace and blessings of Allaah be upon him) as He said (interpretation of the meaning): That Allaah may forgive you your sins of the past and the future, and complete His favour upon you, and guide you on the Straight Path. [al-Fath 48:2]
Shaykh al-Islam Ibn Taymiyah said, in al-Fataawaa 10/296, Concerning the issue of forgiveness of the Prophets sins: Allaah, may He be exalted, does not speak of any Prophet in the Quraan, except He also mentions repentance and seeking forgiveness. For example, Adam and his wife said: Our Lord! We have wronged ourselves. If You forgive us not, and bestow not upon us Your Mercy, we shall certainly be of the losers. [al-Araaf 7:23 interpretation of the meaning]. Nooh said: O my Lord! I seek refuge with You from asking You that of which I have no knowledge. And unless You forgive me and have Mercy on me, I would indeed be one of the losers. [Hood 11:47 interpretation of the meaning]. Ibraaheem said: Our Lord! Forgive me and my parents, and (all) the Believers on the Day when the reckoning will be established. [Ibraaheem 14:41 interpretation of the meaning] and You are our wali (Protector), so forgive us and have Mercy on us, for You are the Best of those who forgive. And ordain for us good in this world, and in the Hereafter. Certainly we have turned unto You [al-Araaf 7:155-156 interpretation of the meaning]. Moosa said: You are our wali (Protector), so forgive us and have Mercy on us, for You are the Best of those who forgive. [al-Araaf 7:155 interpretation of the meaning]. Then he [Ibn Taymiyah, may Allaah have mercy on him] gave further examples, but what we have mentioned here is sufficient. And Allaah knows best.