The purpose of law as well as what exactly deems something lawful does have its contrasting reasoning's since each may vary depending on the region you reside within. In general law serves five main functions: it cultivates and ensures the existence of adequate order, provides resolutions to conflicts, provides a safe haven for individuals and their assets, maintains the structured operation of the civilization, and protects civil liberties as set forth in each nation's constitution.
In reference to its maintenance of order, law must decide exactly what is lawful and what is not. In this same way, the purpose of law remains to provide a basis for which one may lead a lawful life, with the well being of others as a consequence of such a function.
Law is, therefore, existent to maintain the safety of lawful citizens from those who are unlawful. In order to proceed as doing justice for all, it must then be employed equally amongst all, and not just a select few. Law exists as a rigid yet stable force by which people are to follow. It serves as a means to prevent the arbitrary rule of lackluster leaders who may decide to take over whole nations. The purpose of law is to maintain the order of the country despite changes in leadership.
It helps to remind all those who may have assumed new power that what is and isn't lawful remains the same despite their advent into the head of the ruling party. Regulation of power is also what law takes into account as no one, not even the president, possesses full reign over the country due to the existence and practice of law. The purpose of law is to maintain individual freedoms, while still keeping in mind what is moral and right.
In terms of the judicial system, the purpose of law is attached to the way in which judges may rule over cases brought forward for their specific attention. Without the presence of law, there could never be judgment over what is or is not lawful. Therefore, judges would be left to decide based on frivolous beliefs that may have no basis whatsoever.
Law is in existence to further the progress of societies as absence of it would only have whole nations revert back. Law functions to ensure that its citizens have the opportunity to exercise the rights provided to them. It seemingly regulates a lot of what we think and do, though some may not be as obvious as others. It is assumed that, each act we partake in is accompanied by the express consideration of a law or societal rule, and as so, we proceed accordingly.