Most cognitive fallacies stem from the minds need to quickly deal with complex inputs and situations. In many cases they might be warranted in survival situations but often are not very good for long term success, complex situations, and bring about the worst in human behavior. Here is a good link on the Just World Fallacy.
In a 1966 study by Melvin Lerner and Carolyn Simmons, 72 women watched a woman solve problems and get electric shocks when she messed up. The woman was actually pretending, but the people watching didn’t know this. Lerner based these studies on the things he had seen working with the mentally ill. He noticed how he and other doctors, nurses and orderlies would sometimes insult people who were suffering or come up with assumptions about what kind of people they were, or joke about their illness. Lerner thought this behavior might be an attempt to protect the psyche of people facing an abysmal, unrelenting amount of misery and despair