Trying to force companies to keep people longer than they want is how the social safety net works in some places (like Japan) and it's how the US healthcare system works, but both of those are, like, bad.
It's better to make it easier to quit and find a new job and support people in the meantime. Denmark as an example.
But to do this you have to have other ways to push people to stay productive.