It's preparation to become either a professor at a university or an independent researcher at an industrial/government research lab. It won't increase your lifetime earnings or job prospects, but it does open up doors to jobs whose primary allure is intellectual freedom rather than material reward.
If you don't go one of those two routes after a CS PhD, then a CS PhD has rather high negative expected value except in a few special circumstances (e.g., BS from NoName Branch Cappus to PhD from mit/cmu/stanford. But that's not the typical case for non-immigrants.)
How do?
Grants.
Going to school where college is cheap and/or cost of living is low.
Testing out of classes.
Taking a job where your employer will pay for your education.
Living with relatives while attending school on a pay-as-you-go basis.
Different people work this out different ways. The exact details will vary tremendously.
I have done all of the above at various times. I have nearly six years of college and only ever took out one student loan for a boot camp style summer program where I completed a year-long certificate program in eight weeks.
But ability to arrange to do so without incurring new debt is very much a personal matter and depends on many variables, such as marital status, existing dependents, current debt load, existing health issues, etc.