The explanation is as follows: God prepared two paths in the second stage to bring us to the third stage. The first is through fulfilling Torah and mitzvot, as explained above. The second is through suffering. The suffering itself purifies the body, and it forces us to eventually transform our desire to receive into the form of the desire to give, and therefore to bond with God.
This is related to what the Sages state (Sanhedrin 97b): “If the Jewish people repent, good [they will be redeemed]; if not, I will appoint a king over you like Haman [who will afflict you with harsh punishments] and force you to repent.” “In its time, I will hasten it” (Is. 60:22). The Sages explain (Sanhedrin 98a): “If they are worthy, I will hasten it [the redemption]; if they are not worthy, it will be at its time.”
This means that if we are worthy of using the first path, i.e., that of Torah and mitzvot, then we hasten our repair, and we will not require severe, bitter suffering over a long period of time to force us to return to the proper path. If not, however, [the repair] will occur at its time – that is, at the time that the suffering will bring about the repair, and the time of repair will arrive against our will. (That path of suffering includes the punishments of the souls in gehinnom.)
In either case, the repair will be completed in the third stage, which is inevitable given the first stage, and our free will determines whether [the third stage] arrives through suffering or through Torah and mitzvot.