But Sin causes - the sin of Adam, to pass the cup of death upon all creations, and there is no hope. Therefore the power of the soul does not stop doing this refinement before death, and this is the matter of the righteous who died only due to the advice of the snake, per their saying, may their memory be blessed (Bava Batra 17a), that they couldn't be perfected even through the plethora of their actions without this.
But after the dust returns to the earth as it was, and the filth which the snake imposed upon Eve is removed from it entirely, until it returns and is rebuilt - will descend into it the soul with all the strength of its good deeds and the radiance of the heavenly light from which it derived benefit in Gan Eden according to its actions, and will illuminate within its body a great light, through which it will be refined entirely, and will return and heal it from all of the negativities that were made a liability for them from the beginning.
And this matter is explained in the Midrash haNe'elam[concealed Midrash], Parshat v'yera, and this is its language "said our Rabbis may their memory be blessed - the soul, while it is still in its heights is sustained by the light from above, and is garbed in it, and when it enters into the body in the future to come - with this light itself shall it enter...etc.", see there. And in addition there (117a), "the Holy One blessed is He inserts this body under the ground until it decays completely and removes from it all of the bad filth", see there: