Why do bad things happen to good people? This is a vexing theological question if one assumes a loving God. It has come up again in the aftermath of back-to-back hurricanes, Harvey and Irma, which did serious damage to the US and the Caribbean. Most of the victims were doubtless good people.
In some ways this is what they call a "First World Problem." People in much of the world even today, and people in most of the pre-modern world, wouldn't have had philosophical discussions about why bad things happen. Bad things happen, they would say, because bad things always happen: fire, flood, disease, accident, war, betrayal, hunger, quarrels, loss … The list goes on for quite a while.
Even in the modern US, where most of us (when we are not evacuating from hurricanes) can imagine we're fairly good people leading fairly good lives, bad things happen to everybody. One interviewer I heard said she can always get a perhaps reluctant person to talk by saying, "Tell me about a time you were treated unfairly." Then she couldn't get them to shut up!
I guess if someone were born into privilege and had every want catered to, and died unexpectedly and painlessly before anyone they loved died, then maybe nothing bad happened to them during their life (until they died of course).
But it's still a good theological question. Medieval thinkers in monasteries and universities came up with answers, as they did for so many other theological questions. They may not be our answers, but these people were smart and tried to figure things out.
The most obvious answer was one derived from the Old Testament, that everyone was to be punished for the sins of the few. Thus one reads in the Bible about "the sins of the father" being punished in all his descendants. God destroying the earth with floods because of some bad actors, or wiping out Sodom and Gomorrah because some people there threatened His angels, certainly suggest that one can suffer for someone else's fault. Even today, there is talk in some circles of God bringing about hurricanes because the US is not strict enough against sexual sinning.
Medieval thinkers, however, would not have agreed. For the most part, they rejected the idea of the many suffering for the few. Medieval Christianity put the New Testament ahead of the Old, with its emphasis on individual rather than collective responsibility.
So why did good people experience pain and sorrow? The answer was easy to medieval theologians. There were no good people! Everybody was stained with original sin and deserved suffering in this life and damnation in the next. Only because of God's completely undeserved mercy did anyone make it to Heaven at all.
(Medieval Christianity was not "comforting." See more on this here.)
The only really good people were the saints, and they suffered the most of all. All the early martyr-saints had had horrible things done to them for their faith, like being slowly cooked on a griddle (Saint Lawrence). This suffering, for medieval theologians, burned away the sin in them, strengthening them and making it possible for them to become saints. People who wanted to emulate the saints deliberately sought out extremely unpleasant experiences, if not actual martyrdom.