This is a modern way of interpreting religion and morality. It can be considered anachronistic to a fantasy setting, including D&D.

Without getting into the trap of free will, I think a good point has been raised. We know what a world without magic looks like, so it's easy for me to consider any aspect of the D&D world that isn't the same as ours to be in some way influenced by magic. Any creature that isn't an 'animal' likely wasn't naturally selected to exist, this includes elves and goblins, meaning that some part of their essential make up doesn't need to conform to our own preconception on what it means to be completely free of alignment restrictions.