It's not a matter of selfishness. Selfishness is ultimately what necessitates justice to begin with.
As to vengeance, keep in mind that vengeance isn't always just, and justice does not always involve vengeance.
Justice is more about enforcing a standard playing field, if you will. The idea being that the rules and standards we've set are applied to everyone, equally.
That if you break those rules, the damages you've caused, at the very least, will be applied to you as well.
The core concept of these punishments in their nature is to combat selfishness. It's more about maintaining a civilized society, then it is about some kind of personal gain.
Mind you that justice is a very flimsy thing.
nothing is worse than punishing somebody who does not deserve it. It's why vigilantism is ultimately frowned on. Not because it isn't useful, or that it doesn't work, or anything like that. The problem is that there is a solid chance somebody innocent will get caught in the crossfire, or a punishment won't fit a crime.
A system which punishes an innocent person is in effect the same as any criminal who would rob you, kidnap you, and so on.
As such, much in the same way as you wouldn't have an obligation to listen to the demands of someone stealing from you, and moreover would have the right to defend yourself from a would-be aggressor, you have absolutely no obligation to bend the knee to an unjust system.
which of course is why we have such a rigorous standards when it comes to Justice systems. We must assume innocent until proven guilty, because assuming guilt will inevitably lead to innocent people being punished. And if innocent people are being punished, people no longer have any moral obligation of any kind to abide by our systems given law or demands of justice.
The system inevitably collapses in that regard.