...and according to the degree to which they were repaired, so the light progressively entered into them. For as soon as the body is rebuilt after the resurrection of the dead, the soul will immediately enter into it and start to join with it. Nevertheless, many ascents will still remain to be made before it reaches the end goal. Thus we see that the ability of the soul to enter and join with the body depends upon the degree to which the body is purified. First it must be purified from uncleanliness (through the “torment of the grave”) and afterwards from even the slightest residual trace of uncleanliness (after the resurrection of the dead), and this process involves many details. Each time the soul will shine with added luster.
The Soul Returns Gradually as the Body Is Repaired
Kalach Pitchei Chokhmah 42:7