Ancient ancestors of Homosapeiens, ala. "Cave-men" had ethical codes based on what anthropologists and archaeologists can tell although they did not have clear written records and it pre-dated religion. From an anthropological perspective, ancient superstitions were known to be gathered up and became the first psuedo religion which had rules to avoid risk if that counts as a religion. So the first pagan religion which is lost to the annuls of history of late stone age is likely the one you are looking for.
If you are looking for written records of one that is known by name this may fit your bill:
The oldest known law code is that of King Menes of Egypt. It is called
the Law of Tehut and dates to about 5200 years ago. source
Following your line of questioning:
Additionally, the difference between law and 'ethical code' lies in
how each are followed (generally speaking). For example, the Code of
Hammurabi is more of law. Laws are generally imposed, while ethics is
more or less up the the individual.
From a philosophical perspective:
- Axiology gives us a way to measure value
- Ethics gives us a list of "oughts"
- Laws are suppose to be derived from ethics
In practice Laws come from traditions, politic, personal gain, maintenance of power, societal pressures, etc.. and rarely from well formed Ethical arguments of Philosophy to the great upset of many. This is for a number of reasons namely Philosophers have done a poor job making a compelling chain of reasoning going from Metaphysics -> Epistemology & Logic -> Axiology -> Ethics that has been widely accepted. There are a number of reasons for this, namely
- People that currently hold political power have incentives to keep control of that power
- People that are good are making logical arguments tend to be bad at communicating and convincing others of ideas (two different disciplines)
I would say that we are much closer to having a rational chain of reasoning for laws based in Ethics today, but we are not there yet.