That's easy. Someone with a bigger stick than you decides what the law is, and if you break it, they hit you with that stick. Whoever has the biggest stick makes the laws.
You can certainly argue about the morality of how laws are created and enforced, but i wouldn't argue too much with the guy holding the stick 😉