The Bible says, "Thou Shalt Not Kill".
Actually, it's "Thou Shalt Not Murder". And the act of murder can only be committed on human beings. And that really only applies to your fellow X. Heathens are fair game.
That was the interpretation for thousands of years. The law said that if you threw a stone into a crowd of heathens and accidentally killed one of your fellow faithful, then it wasn't murder because your clear intent was to kill a heathen.
In ancient pre-history, we lived in small family groups of a few dozen to a few hundred. As our populations grew, we encountered, who knows how many times, the Stranger Problem; how can you live with the constant fear of the stranger without killing him? In order for civilization to exist, this problem had to be overcome. The earliest forms were probably the discovery of distant kinship, as small groups living near each other probably had tenuous blood connections due to the outbreeding necessary to prevent serious genetic difficulties. Also available, particularly at trading confluences, was honorary kinship, the sacred guest rights. But those are cumbersome and were replaced by religion, by civilization, eventually by nationality, and in due time the rule of law. In some places.
Why is it that in times past, the most horrific acts of cruel barbarity were commonplace wherever two people got together to kill a third? And why is it that in much of the world, these acts are becoming much more rare? Indeed, why is it that a mere five thousand years after the Bible began being written, a modern reader can look at it in astonished horror that these things were considered just and moral?
Because we're still evolving. For a few million years, we evolved to live in small family bands, and it shows. I used to scoff at the notion that small towns were just nicer and safer and all that, thinking it was provincialism at its worst*. It turns out that small towns are safer, nicer, more polite. And that's because everyone knows one another. First, there's social pressure to be nice; when word gets around (and it *will*) your life becomes that much harder if you're a jerk. Of course, the sword swings both ways, the social pressure requires you to conform in all things, not merely in social niceties; Garrison Keillor, of A Prairie Home Companion once said that moving to New York from his small home town was a huge relief because he could finally relax and just be himself away from prying eyes. Another aspect of city vs town life is the presence of strangers; being surrounded by strangers raises your stress levels, making you more unhappy and quicker to anger. Whereas the townsman is open and friendly, the city dweller maintains a personal shield of privacy, ignoring others as much as possible. City dweller, when's the last time you started a conversation with the person sitting next to you on the bus/subway?
Strangers used to represent an entirely potent threat; a stranger was someone who, at the least, might kill you and take all your stuff just because. After a few thousand years, that reflexive fear hasn't gone away.
But I suspect it's starting to, because I don't believe we could have spent 500 generations living with the constant presence of strangers in cities of tens of thousands, and now tens of millions of people without weeding out those people who simply could not abide strangers, without selecting for people who are more tolerant of strangers, more willing to live and let live. Where once it took a great deal of effort to live with strangers, where it was once the case that civilization only managed to independently arise in a very few places, where once we had to invent an omnipresent and angry skybeard to keep us from murdering one another, we can now walk down the street in relative safety.
The world is by no means a perfectly safe place, but it is not what once it was. We have spent thousands of years and hundreds of generations learning, in our bones, how to cope with a civilized world. The changing and advancing of the zeitgeist such that slavery has vanished and racism is waning could be explained by happenstance, by random cultural shift, or it could be that evolution is shifting us away from the paranoid, family-bound apes that we were into an open, embracing humanity ready to live in a global society.
I believe that we developed religion as a desperate necessity to allow us to build our cities, and I look forward to the day when we realize that, like xenophobia, it is a tool that was once useful but which is no longer necessary.
* In the sense that where I live is awesome and everywhere else sucks, not in the sense of a naive misunderstanding of the way the world works.