The Holy Quran says:
4:59 O you who believe, obey Allah and obey the Messenger and those in authority from among you; then if you quarrel about anything, refer it to Allah and the Messenger, if you believe in Allah and the Last Day. This is best and more suitable to (achieve) the end.
These are the three aspects of law in any society. Allah guides us as to morality and based on that the Holy Prophet (s) taught us what is legal and what is not and those in authority teach us how to put that into practice. Without the element of morality or obeying Allah we cannot have the correct law or apply its application correctly.