Consider Socrates' thesis: any amount of external evils (i.e., anything other than vice or loss of virtue) is worth suffering for any gain in virtue. So if twenty years in the Gulag made one slightly less selfish and did not make one more vicious in any way, then it was all worth it.
As far back as I remember thinking about these things, something like Socrates' thesis seemed obvious to me (not that you could tell from my behavior). The man on the rack isn't happy, but if one were to choose between being on the rack and slightly more courageous and not being on the rack, one would be prudent in choosing being on the rack.
Suppose Socrates' thesis is true. This makes some aspects of the problem of evil rather easier to handle. For rarely are we in a position to know that some evil did not either make the person slightly more virtuous or at least offer the peson a reasonable opportunity to become slightly more virtuous. Even if the evil is something like dying in one's sleep, it is not crazy to think that dealing with this death in purgatory might not have made the person more virtuous.
Of course, there is still the question whether the gain in virtue couldn't have as well been produced in other ways. But perhaps this precisely kind of gain of virtue couldn't have been—and different kinds of gain of virtue are incommensurable.
This is not meant to give a theodicy. Rather, it is meant to be one of those posts where I try to identify yet another tool for the theodicist's toolbox.