As already suggested in 1 comment, if a person is "almost" eligible for Moksha, then they have to born again.
The birth cycle ends only after the liberation is attained.
This is analogous to the fallen Yogi terminology from Bhagavad Gita.
A fallen Yogi is a person, who fell more or less short of attaining the final destination. Hence gets reborn and starts perseverance from where it was left.
Similar Q&A during Gita:
BG 6.37 - Arjuna asked, those who possess faith, but wavers mind away from Yoga (state of attaining liberation); After failing to be perfect in Yoga, what state do they attain?
BG 6.40 - Blessed lord said, O Partha, neither here nor hereafter, their destruction happens; O dear, none of those engaged in such auspicious activity, goes to downfall.
BG 6.43 - There [in the new body] they aquire the recollection of intellect of the previous body; And thereafter they persevere (put strong efforts) more for perfection
The examples are trivial. Those who attained Moksha during their birth, were almost perfecting in Yoga till their previous birth:
- Shri RAma
- Shri Krishna
- Even there is story about Ramakrishna Parmahamsa & Vivekananda taking 1 more birth
All of above, apparently got liberated during their last birth. So they would have fallen short of the perfection till their 2nd last birth.
Refer this matching answer:
What will happen to a youth who wants to enjoy life as well as continuing spiritual efforts?