Each of these, the main divisions, and their branches is guarded in two ways. First, by a code of moral behavior. But morality is not enough. So there is also a legal framework. We live by our morals, but we have the laws and both are human necessities.
Some religions live on morals only.
The ethic of this morality is when someone smites you on the right cheek, turn the other cheek. It is noble in a moral sense. If I smite you and you take me to the judge, then the judge will rule that I be punished. So there are both the moral and legal wings in Islam. Hence Islam caters for moralities and for societies.