Law is primarily a coordination mechanism. Traffic drives on the right (or left) — which side doesn't matter much; what matters is that everyone chooses the same side.
Contract law makes commitments credible. Property law defines who can use what and when. Criminal law defines which coordination failures (defection from cooperation) carry sanctions.
The view that law is about justice is not wrong, but it's incomplete. Many laws are Schelling points — arbitrary conventions that stick because everyone expects everyone else to follow them.
Related: ↗ @james / coordination-problems, ↗ @alice / link-topology