This is the basis of contract law. This is the basis of tort law and some criminal law. These laws are essential for an advanced society. The first gives rise to trade and specialization of labor. The second creates peace, security and goodwill.
Many animals are social.
Wolves, ants, chimpanzees and whales come to mind. These laws exist to promote the well-being of the species. When a member of a wolf pack violates a law he is punished by other members of the pack. If violation of the rules is widespread, the whole pack is punished by nature. The pack ceases to operate harmoniously, food becomes difficult to acquire and members die.