I think a lot of variables all line up when terrible things happen. I am reminded of bad outcomes in the hospital. When a malpractice event occurs, the investigation nearly always reveals a series of unlikely events that happen coincidentally to lead to the mistake. There is layer after layer of preventive procedures, training and engineering controls to prevent mistakes, but they happen when "freak" events occur in a series. I think the same sort of improbable events lead to these shooters.
Mass murderers have almost by definition some element of mental illness. But mental illness is common in the population. Then there are guns. But guns are common in our population. And then there are all of the personal and social circumstances that surround these particular individuals that commit these crimes. Many people go down these paths, I believe, but most are diverted at some point onto another path that leads away from mass murder. The two main variables that are possibly controllable are mental illness and availability of efficient weapons.
Another factor is the culture of guns. I think a universal healthcare system that had mental health coverage would act like a large blanket that would catch and divert many kids and adults into treatment. I think gun laws that raise the bar for gun ownership would also divert some of these individuals from their path to destruction. Both of these social measures would constrain the culture of guns.
In any group of millions of individuals there will be aberrancy. We will never be able to identify those "needles in the haystack" that are going to commit mass murder. We can offer treatment to all and catch most of the "needles" in the blanket, though.