Preceding causes of the afflictions
From the book: The Gospel according to the Spirititism - Allan Kardec

While there are evils in this life whose primary cause is man, there are others to which he is completely alien, at least in appearance, and which seem to affect him as if by fate. These are, for example, the loss of loved ones and the loss of those who are the support of the family. They are also the accidents which no foresight could have prevented; the reverses of fortune which frustrate all prudent measures; the natural plagues, the diseases of birth, particularly those which rob so many unfortunates of the means of earning a living by their work: deformities, idiocy, cretinism, etc.
Those who are born in such conditions have surely done nothing in this life to deserve, without any compensation, such a sad fate, which they could not avoid, which they are unable to change by themselves and which leaves them at the mercy of public pity. Why, then, do such unfortunate beings exist, while next to them, under the same roof and in the same family, there are others favoured in every way?
What shall we say, lastly, of those children who die at an early age, who have known nothing of life but suffering? These are problems which no philosophy has yet been able to solve, anomalies which no religion has been able to justify, and which would be the negation of the goodness, justice and providence of God, on the hypothesis that the soul is created at the same time as the body, and that its fate is irremediably fixed after a few moments' stay on earth. What have these souls, who have just left the hands of the Creator, done to suffer so much misery in this world, and to deserve any reward or punishment in the future, when they have been able to do neither good nor evil?
However, in virtue of the axiom that every effect has a cause, these miseries are effects which must have a cause; and since we admit the existence of a just God, that cause must also be just. Now, since the cause always precedes the effect, if the cause is not in the present life, it must be prior to this life, that is to say, it must belong to a preceding existence.
On the other hand, since it is not possible for God to punish someone for the good he has done or for the evil he has not done, if we are punished, it is because we have done evil. If we have not done wrong in this life, we have done wrong in another. No one can evade this alternative, in which logic determines on which side God's justice lies.
Therefore, man is not always punished, or wholly punished, in his present existence, but he never escapes the consequences of his faults. The prosperity of the wicked is only momentary, for if he does not atone today, he will atone tomorrow, while the sufferer is atoning for his past. Disgrace which at first seems undeserved has, therefore, its reason for being, and the sufferer can say in all cases: "Forgive me, Lord, for I have sinned".