Justice and mercy are not opposites.
Favoritism is the opposite of justice.
Favoritism pretends there was no harm. And that’s wrong.
James 2:9 (AMP)
But if you show partiality [prejudice, favoritism], you are committing sin and are convicted by the Law as offenders.
Justice acknowledges sin. Mercy forgives it. And that’s good.