Earlier quoted context omitted.
what about making sure the person who did it to you does not profit from it?
By itself, that seems like sunk costs to me - preventing someone else from profiting from a disadvantage they put you at does not necessarily remediate said disadvantage. But there's certain ways in which it could be "rational" - e.g. preventing them from doing you harm again in the future by scaring them off with your revenge, evening out some sort of competitive position so that you are on the same level again, or…
Carrying out a threat is, therefore, always irrational. However, if I could make you believe that I would carry out the threat, then I could get you to not do X, which would be good for me.
If I can modify my own mind so that, if you do X, then I am obsessively driven to carry out Y—"revenge"—and I make this obvious to you, then modifying my mind in that way is rational for me to do. (Of course, the only key part is making you believe that my mind works like this. But as a species, I think humans are not especially good liars—probably for good reasons, so that threats and promises are possible—and the most reliable approach to making you think I'm like that is to be like that.) I think this is why there is a built-in drive for revenge.
Now, the drive for revenge doesn't always win. In the ancestral environment, carrying out revenge against the wrong enemy may simply get you killed. It's possible that "knowing when to back off" has been selected for. (Perhaps the neural circuitry sometimes perceived natural forces like rain, or stronger creatures like tigers (possibly the relevant evolving happened before we got good at hunting), as the "enemy".) Which then opens the door to trying to intimidate the other party even further so they don't try for revenge, or to bluffing that you're not intimidated, or to guessing (perhaps incorrectly) that the other side is bluffing, and so on.
Anyway, that is the mess we are left with.