All perfect praise be to Allah the Lord of the Worlds. May His peace and blessings be upon our Prophet Mohammad and upon all his family and companions.
Serving the public as much as possible is among the duties of the state, and providing social security is part of these duties. This system (Social security) takes care of the elderly who meet the stipulated conditions, such as paying social security contributions, be that in advance or by installments. Therefore, whoever pays the specified contributions meets the stipulated conditions, and this is permissible from the perspective of Sharia.
In fact, this is better than the expression "Purchasing years of service credit" given in the above question, because purchasing is used in commercial contracts while the above form is a contract based on kindness; otherwise, it would have been forbidden in principle. And Allah The Almighty Knows Best.