Religiosity has appeared in the course of evolution and is advantageous for human kind. And although it is believed that it is religion that teaches us what's right and what's wrong, I think religion evolved to substantiate our morality. Brain likes to justify our beheviors.