Our innate sense of justice, of how things ought to be, clashes with how things are. Thus we have divine retribution. We ought not die, but we do, so after we die we live supernaturally. Dissonance can give way to religion, generally speaking.
Religion is the result of changing the world to fit your beliefs. Lack of religion is the result of changing your beliefs to fit the world. Cognitive dissonance can be resolved in one of two ways.