There is a difference between “righteous” anger and “unrighteous” anger. Some people have a duty to correct others (ie fraternal correction) such as parents, teachers, public officials, police officers, judges, religious superiors. Fr Serpa of Catholic Answers answers a similar question here:
Doesn't Jesus' anger contradict being sinless? Ask an Apologist
Ok, so. Jesus was without sin…Sinless. Jesus was angered in the temple and at the fig tree. Anger is one of the seven deadly sins… So…How is he without sin…
This article also talks about the difference between “righteous” anger vs “sinful” anger:
Fr Callan and Fr McHugh also talk about the different types and degrees of anger in their work “Moral Theology” (the work has the nihil obstat and imprimatur):
Anger .—Anger is sinful when it deviates from reason, as to its matter or its manner.
(a) Thus, it is unreasonable as to its matter (i.e., its vengeance) when it punishes unjustifiably (e.g., when the person punished is innocent, when the penalty is excessive, when the legal order is not followed, when the motive is not justice or correction, but hatred, etc).
(b) It is unreasonable as to its manner (i.e., the degree of excitement felt or shown) when temper goes beyond measure. Great anger is not sinful when a great evil calls for it (e.g., the anger of Our Lord against the money-changers in John, vi. 14 sqq.; that of Mathathias against the idolatrous Jew in I Mach., ii. 24); but to fly into a rage at nothings or trifles is sinful.
Gravity of the Sin of Anger. —(a) If anger is sinful on account of its matter, it is mortal from its nature as being opposed to charity and justice. He that is angry against his brother is worthy of hell fire (Matt., v. 21, 22). It may be venial, however, on account of imperfection of the act (e.g., the sudden impulse to strike down those who do not agree with one’s opinions) or the lightness of the matter (e.g., a slap or push or box on the ears given a naughty child when a word of reproof would have sufficed).
(b) If anger is sinful on account of its manner, it is venial from its nature; for excess in an otherwise indifferent passion is not a serious disorder (see 2450). But the sin may be mortal by reason of circumstances, as when an angry person acts like a wild man, curses and swears, breaks the furniture, gives serious scandal on account of his position, or the time or place, or injures his health by the violence of his paroxysm.
Is Anger a Graver Sin than Hatred and Envy? —(a) As to its matter, anger is less grave than hatred and envy, for it pursues evil under the guise of spiritual good, pretending at least that the harm it intends is just, whereas hatred and envy pursue evil precisely as it is injurious to another, or as it is a means to one’s own temporal and external good or glory. Likewise, anger is less grave objectively than concupiscence, for the voluptuous man aims at utility or pleasure, whereas the revengeful man aims at what he makes believe is just.
continued….