It was developed over many, many years by humans in effort to understand life and our place in it. It evolved into a communal type of institution and system of law through which human conduct was better aimed for civilization and greater peaceful relations between people, which led to outlaws and rebellions and penal consequence for failure to observe the laws set up as codes for human conduct.
I think that could have been done without religion however religion I think gave the system of law a false authority which probably made implementation easier.