Justice does not mandate that all rules be followed. It mandates that all rules be equitable, and be enforced equitably.
Finally, while using the rule "Do whatever leads to the best outcome" is a perfectly good way to operate as an individual, it is unenforceable on a societal level. This is why we have other rules. It's impossible to figure out just what has the best consequences, so we try to produce more concrete rules that improve consequences overall (hopefully which don't have too many consequences of their own).
Following the personal rule "Do whatever leads to the best outcome", even when it goes against society's laws, is called civil disobedience. When done for a good cause, it is not generally vilified. The catch to civil disobedience is that you must accept the consequences of your actions.