If you believe, as we do, that the Prophet (blessings and peace of Allah be upon him) was human, this means that you believe that he (blessings and peace of Allah be upon him) used to eat, drink, sleep, wake up, marry women, and go to the bathroom. Moreover, one of the implications of his being human is that he could forget and make mistakes, and he might behave in a manner other than what is more appropriate and more proper. In fact the majority of scholars state that the Prophets were not protected from committing minor sins. And there is textual evidence to that effect.
See questions no. 7208 and 42216.
Have you not read the words of Allah, may He be Glorified and Exalted:
{He frowned and turned away,
when the blind man came to him.
How do you know? Perhaps he may be purified,
or he may pay heed and benefit from the reminder.
But as for him who is indifferent,
you give him your full attention,
although you are not to be blamed if he does not want to be purified.
Yet as for the one who has come to you eagerly [seeking purification],
for he fears Allah,
you allow yourself to be distracted from him} [`Abasa 80:1-10]?
This is a clear rebuke from Allah, may He be Glorified and Exalted, to His Prophet (blessings and peace of Allah be upon him), which resulted from how he dealt with that blind man, which was contrary to what would have been more appropriate, as he should have paid attention to him and showed him kindness as he deserved.
Similarly, have you not read the words of Allah, may He be Glorified,
{May Allah pardon you! Why did you give them permission [to stay behind] before it became clear to you which of them were telling the truth, and which were lying?} [At-Tawbah 9:43]?
The great scholar as-Sa`di said in his Tafsir: That is, He has pardoned you and forgiven you for your decision.
End quote from Taysir al-Karim al-Mannan, p. 338.
This is a clear rebuke for the Prophet (blessings and peace of Allah be upon him) having given permission to those of the hypocrites who asked him for permission to stay behind from a military campaign. This is one of several examples which show that the Prophet (blessings and peace of Allah be upon him) was human, as forgetfulness, error and anger are normal for humans. But that happened rarely in his case, in contrast to one who is like that most of the time or all of the time, and he is led by his emotions in all or most of his affairs.
Understanding the above may help you to answer your question and resolve your confusion, especially if you ask yourself: why did this specific confusion not arise in your mind when you came across these verses, such as thinking to yourself: if the blind man came asking you to teach him about the truth and goodness, and you turned away from him, there would be no blame on you because this is how the Prophet (blessings and peace of Allah be upon him) behaved?!
Rather we say that you are to blame for your behaviour, and you have no right to justify your actions based on the story of the blind man, Ibn Umm Maktum, and what happened to him.
You are exactly the same as one who wants to do something that Allah has forbidden, and he says: Adam (peace be upon him) was forbidden to eat from the tree, but he went against that and ate from it!
Or you are like the one who kills a soul whom it is forbidden to kill, and tries to justify it by saying that Musa (peace be upon him) struck a man with his staff and killed him!
And there are other examples of invalid and unacceptable justifications, to the extent that the stories that Allah has told us about in His Book have become a disaster for the one who does that, as a result of his poor understanding of the humanity of the Messengers and Prophets.
It is not proper etiquette on our part to seek out such mistakes made by the noble Messengers and Prophets, or to aim to collect such stories and talk about them a great deal. In fact, Ibn al-`Arabi (may Allah have mercy on him) said: It is not permissible for any of us today to speak about that (i.e., Adam’s sin) unless he mentions it in the context of discussing a verse or hadith. As for bringing up such topics on his own initiative, it is not permissible for us to do that when speaking of our own parents and grandparents, so how about the greatest of our forefathers and the first Prophet, whom Allah pardoned, turned to him in mercy and forgave him?
End quote from Ahkam al-Quran by Ibn al-`Arabi, 3/259.
Allah, may He be Glorified and Exalted, did not tell these stories about His Prophets in His Book in order to shame them or for them to be an example to follow in their errors, so that someone could say: I can get angry as the Prophet of Allah got angry, and so on. The lesson in these stories is the way in which the prophets behaved after that, and how they showed servitude to their Lord after they had committed their mistakes.
Abul-Ma`ali al-Juwayni (may Allah have mercy on him) said:
The correct view that we believe in is that the prophets were not protected from committing minor sins, for the verses of the Quran narrate stories that are filled with the minor mistakes that they made, and show that they spent the rest of their lives seeking forgiveness for these minor sins and mistakes that they committed.
End quote from Ghiyaath al-Umam, 94.
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) said:
Allah tested the prophets with sins so as to raise them in status by means of their repentance, and to increase their love of Him and their joy in draw close to Him. For Allah loves those who repent, He loves those who purify themselves and He rejoices greatly at the repentance of the one who turns to Him in repentance. What matters is the perfect end, not the imperfect beginning, because Allah may decree that a person will be granted a high status, but he cannot attain it except by means of what Allah has decreed for him of effort or trials.
End quote from Majmu` al-Fatawa, 20/89.
Based on the above, the fact that the Prophet (blessings and peace of Allah be upon him) got angry is not something to be taken as an example to be followed; rather his striving in worship of his Lord after the error that he made is the example that we should follow and strive to emulate.
Moreover, part of the wisdom behind that is so that the ummah may learn that absolute perfection is for Allah, may He be Glorified and Exalted, alone.
Al-Hasan al-Basri (may Allah have mercy on him) said: Allah, may He be Exalted, did not mention the sins of the prophets in the Quran in order to shame them; rather He mentioned them to highlight how He blessed them by pardoning them, so that no one should despair of His Mercy.
And it was said that He tested them with sins to show that absolute purity and might is His alone, so that all creation on the Day of Resurrection will meet Him feeling subdued because of what they committed of sins.
End quote from Tafsir as-Sam`ani, 3/22.
Furthermore, you should understand that the anger of the Prophet (blessings and peace of Allah be upon him) was a mercy for those with whom he got angry, and it brought reward for them and was an act of charity towards them, as it says in the hadith mentioned above in your question. Allah the Almighty indeed speaks the truth:
{There has come to you a Messenger from among yourselves; it grieves him that you suffer, and he is full of concern for you; and towards the believers he is compassionate and merciful} [At-Tawbah 9:128].
Thus you should realize that there is no contradiction between the Prophet’s anger and the hadiths which warn against anger, or the fact that in most cases the Prophet (blessings and peace of Allah be upon him) resorted to forbearance, forgiveness and overlooking, even with the enemies who were the most harsh and vicious in fighting Islam and the Muslims.
After that, will there be any confusion about the hadith of `A’ishah (may Allah be pleased with her), who said: Two men came to see the Messenger of Allah (blessings and peace of Allah be upon him) and spoke to him about something; I do not know what it was. They made him angry and he cursed them and reviled them, then when they left, I said: O Messenger of Allah, some good will reach everyone but it will not reach these two. He said: “Why is that?” I said: Because you cursed them and reviled them. He said: “Do you not know what condition I made with my Lord? I said: O Allah, I am only human, so any Muslim whom I curse or revile, make it purification and reward for him”? Narrated by Muslim (2600).
For more information about this issue, please see the answers to questions no. 147389 and 139912.
And Allah knows best.