When applying to PhD programs in Computer Science, how much does subfield/specialty selection matter? I recently finished applying to several Ph.D. programs in Computer Science, and as part of the application process I had to select one or two subfields of CS that I was interested in. For many of them I selected specialties like Artificial Intelligence and Machine Learning, and I've already started receiving emails from professors in those fields who would be interested in advising me.

My statements of purpose mentioned that I was "particularly interested" in AI and Machine Learning, and whenever possible I checked those boxes on the application forms. However, I'm also interested in other specialties (e.g. Theory), and although my statements of purpose do mention that I have varied interests in CS, I never specifically selected Theory as one of my desired specialties.

Have I painted myself into a corner here? If I'm accepted to a Ph.D. program in Computer Science and I selected specialty X on my application, can I still conduct research in specialty Y?
"Can I still conduct research" has some different interpretations which bear on your question. The short answer, at least in my experience, is no, you have not painted yourself into a corner. But let me elaborate:


There can be significant overlap between AI/ML research and Theory, so you may end up finding a thesis project which combines aspects of both to your satisfaction. 
It's not at all uncommon for students to bounce around a little bit after they enter a program, and to have side projects in tangential areas. Even if you do your primary research in machine learning, you could participate and publish in other collaborations. I did this for a couple of different projects just to chase my own interests.
As @ben-bitdiddle alluded to in his comment, many programs (even most in my experience) are not so strict in locking down new Ph.D. students to a particular area/advisor. It can obviously present a problem if you're not aligned with one after your first couple of years, but at the beginning I think this can be very beneficial.
One important caveat is that if you're being funded by a faculty member on a research assistantship, you'll be expected to be doing research in that person's area and it likely won't be looked on kindly if you're spending a lot of time on other projects. This is something to discuss with the faculty in question, though, before you accept the RA if you have questions.


Many people end up doing something different for their dissertation than they indicated on their graduate application, so I wouldn't sweat this point too much if I were you.

Lastly, you mention that you've applied to several programs. I'd ask some questions surrounding this issue and consider those answers as I made my decision about which offer of admission to accept.