Before the Egyptian Empire a group of African people banded together and helped one another freely, that's how they came to be together. The empire, their folly, sprang out of their misunderstanding of reality. The people did not know what the Earth was so they made up these strange theories about life and death, Egyptians thought that some of their people were able to bridge the gap between the living and the dead, they ended up becoming pharaohs. This belief likely arose from individuals who learned and were able to predict seasonal cycles. The people saw that someone could predict when the seasons would change and assumed this person could communicate with the gods in order to obtain this knowledge.
The idea wasn't evil in its original form, although it was incorrect. The pharaoh in conjunction with the dead and the gods would help the people of the empire prosper. The people believed this so much that they gave to the pharaoh in thanks, but after time went by the pharaohs children became so pampered that they began expecting to be pampered. They became greedy and arrogant and when they weren't pampered they believed the people were forsaking the gods so they punished the people who did not obey them. This idea evolved into what we have today.
More and more 'laws' came about and the people were less and less free. The growing lack of freedom angered some people who then took their anger out on others, now laws were needed to protect the people from the people who were pissed off at the laws. We never realized that the problem was being caused by the erosion of freedom in the first place, so freedom was eroded more and more and the problem got worse and worse. Now we're so far removed from our days of freedom and we don't remember that the laws were never needed in the first place.
Laws were never invented for the purpose of protecting the people from each other, they were invented because we mistakenly believed someone was god and he abused that power to serve himself.