As civilization developed and people began to live together in large communities, conflicts were inevitable. In order to settle disputes, shared values and rules of conduct developed from mere custom into formal laws. In time, courts were established to enforce those laws.
The development of laws, with courts to enforce them, meant that similar actions came to be treated in similar ways. Therefore, people could understand, ahead of time, what the consequences of their actions might be.