Not for this does he deserve to be entirely shut out from reward: because all this may happen without mortal sin; and it is only mortal sin that occasions the loss of charity, to which the reward of life everlasting is due. Such persons then must be cleansed in the next life, before entering upon their eternal reward. This cleansing is done by penal inflictions, as even in this life it might have been completed by penal works of satisfaction: otherwise the negligent would be better off than the careful, if the penalty that men do not pay here for their sins is not to be undergone by them in the life to come. The souls then of the good, who have upon them in this world something that needs cleansing, are kept back from their reward, while they endure cleansing purgatorial pains. And this is the reason why we posit a purgatory, or place of cleansing.
Thomas Aquinas, Summa contra Gentiles 4.91