Did you ever wonder where the very first building code was mandated. Believe it or not, it was in the Bible. Moses actually brought building safety laws to the Israelite nation as part of their original laws for living in a new land.
"When you build a new house, make a parapet around your roof to make it safe so that someone doesn't fall off and die and your family become responsible for the death".
(Deuteronomy 22:8 MSG)
A parapet is a half wall and would fall under safety railing height code in today's code books. I haven't see such straight forward talk in current code about why we do what we do, but apparently the idea of protecting your property and the well being of others is not a new idea.