In most fields in the US including CS (especially theoretical CS), you are admitted to a "program", essentially to a department. The decision about an advisor comes later. If you enter with a BA/BS then it can be much later (years). The first task is to take whatever courses are necessary to get you through prelim/qualifying examinations, which are all on advanced topics. Even some MS entries may need some courses and need to pass quals. About that time (bit earlier or later) you make arrangements with an advisor for your dissertation work.
In some scientific fields the PI decision may need to come earlier, but, perhaps, only in general - with a group or lab, rather than an individual.
But, yes, they are usually separate decisions. In some places in Europe it is quite different and "admission" to a program is the same thing as being "hired" by a PI. It isn't like that in US. A few situations are more like the European model, with a grant funded PI who is able to "admit" doctoral students into their lab or working group. But this is rather rare in US and most funding and admissions is at the department level. See the answer of Bryan Krause for more on the alternative model. Applied fields might be more like this, including Applied CS, since a PI might have funding to work on a specific problem.
Until you pass quals in US, all agreements with PIs/advisors are tentative and conditional.
Funding: On the standard US model, most students are funded as TAs or (less frequently) RAs. This includes forgiveness of tuition fees as well as a modest stipend sufficient to live on. Getting such a position is, again, usually up to the department, not the individual professor. Large departments that teach undergraduate courses (math, CS, ...) need a lot of TAs.
A few students are funded by employers, but this seems to be rare currently. It was more prevalent in some places in the past. And, a few international students are also funded by home governments.