Laws are made when society feels that an act, behavior or event, needs to be controlled and punished if violated. Laws are set in place to remind others if they make the choice to break or violate a law, there will be some form of punishment.
Everyone is raised differently and has their own idea of what is acceptable or allowed. In some cases this thought is distorted and without laws to protect others and keep individuals in check, so to speak, every individual in the world would take advantage of the opportunity to just instantly react to any event without regard for consequences. The world would be a lot more chaotic than it already is.
Depending on the country you live in the laws may differ based on many factors. Some laws in countries are solely religion based and violating that belief can bring punishment. For most countries though, laws are set forth because one or more groups of individuals has become a victim, has been violated unjustly in some way or to prevent an unlawful event to happen in the first place.
The laws are usually implemented by gaining recognition either by public outcry for something to be done to control or monitor a matter or by one who argues it’s relevance in a higher court or governing entities and wins.
Of course, general laws to protect life and the welfare and safety of the public are common and usually standard in some form for nearly all countries. Laws are reviewed and implemented based on past experience with violators, need, relevance and many other factors. These laws are usually written by a governing or legal entity to ensure proper wording and recognition that a problem exists and needs control, consequence or monitoring at some level.
Once written, the matter is voted in some countries, in others it is simply decreed and ordered by the ruling government. In some countries the way a law is written may be challenged and viewed or interpreted incorrectly. In cases where the challenge is justified, a law may be amended or rewritten accordingly to be interpreted the way it was intended or modified to clarify purpose.
How laws are made will differ from country to country as well based on economic, educational, financial, religious and numerous other intentions a country feels is important to their sustainability, safety and image. In some cases any individual would not be able to attempt to challenge or modify a law implemented by their government. In the US however, individuals challenge laws daily in the form of appeals, motions and rulings.
Some laws have been established in countries since their initial creation, others have been taken over by other countries in war and forced to accept the new law and adapt or face punishment. In some cases opposition to accepting new laws during takeovers, is rejected. This rejection can lead to terrorism, war and ongoing social unrest. It really depends on how advanced the country is technologically, socially and economically as well as how great the need is to have some form of order.