Moses, in Deuteronomy, explains the necessity of a functioning justice system to the wellbeing of the nation. There is a difference between 'legal' and 'just.' Courts with either corrupt judges or bad laws can apply a correct judicial process and arrive at a wicked result. The ultimate source of just laws is the Torah. Anything else is simply based on human reason and the application of force.