Religion is, at its core, the grout that fills in the spaces in our understanding of the physical world and a psychological survival mechanism that reduces that discomfort we feel when something we can't comprehend happens.
Thousands of years ago, the sun was a god riding across the sky, and that was an ummutable fact. It had to be, because we had no frame of reference to even begin to comprehend was the sun actually is. But, eventually man's knowledge of the world grew through science and observation, and god retreated.
Just a few centuries ago, sickness was caused by evil sprits, and some people were cured by god through ritual and prayer. Then, we learned about microbes, bacteria and infection and god retreated again.
A side effect of our unique intelligence is that our brains try to find logical patterns in everything we observe. Pattern recognition is how our brains operate every day, from recognizing faces of people we know, to making scientific discoveries. It is the key component in our intelligence. Because of this, we don't like chaos. We don't like randomness. So, when something tragic happens that has no logical reason, no meaning, we try to comprehend it by applying comfortable patterns to it. 20 children shot dead in a random act of violence. Something that is incomprehensible to us. Rather than accept that it just happened for no greater reason than one person's mental instability, we have to try and comfort ourselves by saying that there must be some greater purpose, some higher reason.
God allowed it to happen because...
God needed more little angels...
God is punishing us because...
These beliefs, as flawed as they are, are a salve which soothes our brains, which are working overtime trying to fit an incomprensible event into a pattern we can recognize.
Not everyone needs these beliefs to make sense of things. There are people who can deal with an event like this for what it is. But for those who still can't, it helps to understand why. It's not their fault, its how the brain works. The more understanding we have of the world around us, the more we grow out of it, but we're not quite there yet.