Prudence is the virtue anger needs
The key to understanding how anger about such losses or gains could lead to a virtuous, or let's say a righteous act, is in another virtue - the one Thomas calls prudence. Prudence is the form wisdom takes on within human practices. Its goal is wise action shaped by the particular context in which it is needed. The prudent person knows how to calibrate the next thing she does so that it leads will to the specific end she is pursuing.
This "know how" in turn comes through counsel. I know the next practical step not because I have memorized formulas in right action, but because I can learn from others, past or present, in ways that will instruct me in the art of finding the next right thing.
Prudence is the key to understanding righteous anger because anger is supremely a passion that demands activity. Anger wants action, as the therapists teach us. It pumps blood through my body, it makes my muscles flex and my jaw clench, and so prepares me for some bold and likely aggressive act.
But this next act, as any parent or teacher knows, is likely not to be the right one. That's because I will be tempted to simply act, rather than to seek counsel to ensure that I act prudently. Most likely I will act out of a desire for revenge: to cause equal or greater harm. What I need in that moment is the outside input that can help me shape my act in accordance with reason. This is how, Thomas says, the neutral passion becomes meritorious passion: anger becomes righteous.
Righteous anger has a gift to give
Anger's desire for action is in the end its real gift. Notice how anger and sorrow are different sorts of passions. In sorrow, what is taken from me is joy. I long for the lost joy and am tempted to become even more passive. Depression takes me to the zenith of inactivity. Even getting out of bed or calling a friend feels like too much action.
Anger though is all about action. Yes, to act too brashly, too quickly, to seek revenge on the one whom I perceive to have harmed me. Or even to harm the nearest one to me regardless of their involvement (the sin of kicking a dog or abusing a child). Still: anger calls me to act, and for all its risky unhinged-ness, this is potentially a good thing.
Disordered, which is to say un-counseled by practical wisdom, anger can lead to harm. In these cases we make matters worse by calling our anger righteous: that self-justifying claim may in fact be blinding us to the real price of our next act.
But well-ordered, anger can draw us into deeper community with God, ourselves, and others. First comes the passion itself: I am angry and primed for action. Then comes the seeking of counsel, so that my desire for action can shift from the immediate to the prudently discerned. Finally comes the act itself, which anger was calling for in the beginning, now tempered by practical counsel. In such moments I am enacting a right and righteous anger.
And on those days when a loss or an unwanted gain is enough to make me wish to withdraw from the world of human activity, anger may be just the gift I need.