You've probably heard religious apologists assert that if God didn't exist, the world would be an unjust place where some people were never rewarded or punished as their behavior deserved. (They usually hold back from explicitly stating the conclusion, "Therefore, God must exist, because it would make us very sad if he didn't," probably out of subconscious recognition that this would make the fallacy too obvious.) As prominent a religious figure as Pope Benedict has endorsed this reasoning.
Claims like these arise from a fundamental bias of human psychology called the "just world" hypothesis, first described by the psychologist Melvin Lerner. In his experiments, Lerner found that people are uncomfortable believing that suffering is random, that sometimes bad things happen for no reason at all. Instead, we prefer to believe that people must have done something to deserve what they get. This is obviously a reassuring and comforting belief, which explains its wide appeal. (If bad things only happen to those who deserve it, and I'm a good person, then I can be sure that nothing bad will happen to me.) Belief in the just world can be thought of as a failure to apply the null hypothesis in the moral domain: rejecting the explanation of chance, we prefer to believe that everything that happens is deserved.
But the problem is that, however much we'd prefer to believe otherwise, the world is random and sometimes bad things do happen for no reason. And because it encourages us to look down on victims of misfortune as deserving their fate, the just world hypothesis usually leads to worse injustices. For example, it lies behind the common belief that people who've been unemployed for a long time must be lazy (and therefore not deserving of a social safety net or other help), or the belief that rape victims are at fault for being raped if they were dressed "provocatively":
Afterwards, they said that the 22-year-old woman was bound to attract attention. She was wearing a white lace miniskirt, a green tank top, and no underwear. At knife-point, she was kidnapped from a Fort Lauderdale restaurant parking lot by a Georgia drifter and raped twice. But a jury showed little sympathy for the victim. The accused rapist was acquitted. "We all feel she asked for it [by] the way she was dressed," said the jury foreman.
But religion, more than anything else, encourages and supports the just-world delusion. By postulating an all-powerful god who orders events, it offers an easy one-size-fits-all explanation for any misfortune: the victims were sinners, and God was punishing them. That's why a Harvard study, from one of the links above, found that
...people who have a strong tendency to believe in a just world also tend to be more religious, more authoritarian, more conservative, more likely to admire political leaders and existing social institutions, and more likely to have negative attitudes toward underprivileged groups. To a lesser but still significant degree, the believers in a just world tend to "feel less of a need to engage in activities to change society or to alleviate plight of social victims."
The just-world belief is found throughout human culture. It has one of its most extreme expressions in Hinduism's caste system, where each person's station in life is presumed to be the result of sins or virtues from a previous existence. But it finds expression in evangelical Christianity as well, in an even more ridiculous (if no less morally outrageous) form: the belief that everyone in the world who isn't a Christian is deliberately suppressing their knowledge of the truth.
As already mentioned, just-world believers tend to show less concern for the suffering of others and less desire to work toward creating an actually more just society. Ironically, belief in a just world impedes justice. When you believe that God is in charge and everything will work out for the best, this can't help but detract from the urgency of attempts to create a better world by our own effort. How much human suffering has been ignored, how many evils allowed to persist, because of the belief that the downtrodden are sinners who deserve what they get, or that injustice should be patiently endured rather than actively battled? If we truly care about fairness and seeing that justice is done, we need to give up the harmful belief that higher powers control the course of events, and recognize instead that the only moral order in the universe is what we create for ourselves.