I'm a master computer science student. I decided to leave the academia after graduation, but I'm still into research and would like to do personal research independently for like 10 years. Suppose I publish a lot of papers in valuable journals, is it possible to get a PhD after that somehow?
I think you can do research in your own time, but I think getting your work published is hard where you are not affiliated with a university or research institute. You have the advantage that you will not use precious resources from the institute as you will be doing the research in your own time, but you probably do not have a large amount of priority over the normal PhD's and postdocs.
I think you should write a research plan, i.e. where do you want to go with your research. Writing such a proposal will show a supervisor you are serious and have some research skills (provided the proposal is any good). Once you have a number of publications, molding those into a PhD thesis is quite possible. In the Netherlands for example it is quite normal to bundle your papers, and write an introduction and summary as your PhD thesis.
I do think performing research next to a normal job can be challenging, as research tends to take a lot of time. So be prepared to let your PhD take 10+ years (possibly making it obsolete), or sacrifice a lot of spare/family time.
Some universities offer the option of a 'PhD by published works'. See this question for more information. Is that the sort of thing you're looking for?
Technically there are ways to do this (at least in Europe, different countries are different). In practice however, doing PhD work is hard enough when doing it officially part-time with a set supervisor and approved plan. Without a supervisor, you need to be exceptionally exceptional to get a PhD thesis written (and sufficient academic papers published to satisfy expectations).
Think about it this way, the vast majority of PhD proposals in applications are not quite good enough (to execute), so the first thing a supervisor does is change the plan.
PhD studies are studies, same as master degree. So you need to cooperate with university or other scientific institution that has been licensed to grant this degree. Same as you cannot get driving license without applying to the road police (regardless how well do you drive), PhD degree also cannot "emerge automatically" from the number of published articles or the like.
Some institutions may be willing to review existing publications and grant the degree on that basis but generally anyway it must be institution, supervisor and, most often, topic. Many will not allow this path so I would advice to check if you can find one, before you start.
However it is not uncommon for the scientific institution to allow PhD studies without providing the funding (funding may be provided, for instance, by the company where PhD student currently works, or maybe PhD student have enough resources to support himself).