Your choice of PhD topic can give you a slight head-start in a particular career path if it matches well to the work done in that position. However, choosing a topic (as opposed to a discipline) that does not match your later career path does not harm you, except to the extent that it forfeits this small advantage. If you undertake a PhD in a particular discipline (physics, maths, economics, psychology, etc.) you should acquire the ability to learn new topics in that discipline within a shorter time than it would take you to do another PhD in that topic. Hence, once you have completed your PhD in a particular discipline, it is usual that you can move around with reasonable ease, so long as you are willing to put in some time to learn a new topic.
For the most part, your PhD is an accreditation that signals high-level knowledge of a subject area and the ability to undertake research at a level that can be published in peer-reviewed scholarly journals. Most PhD graduates go on to publish papers in scholarly journals and this gives them some claim to expert knowledge in particular topics, but also a high-level of general knowledge in their chosen discipline. Most employers of specialists see it this way, and in my experience it rarely matters what your particular dissertation topic was, though it may matter what topics you have published in. (Besides which, in most cases your dissertation is sufficiently abstruse that eyes glaze over when you try to explain it.)
Choosing a discipline for your PhD study is important, but it is not a huge problem if your topic turns out to be substantially different from what you want to practice later. Your program should give you a good enough knowledge of the discipline that learning a new topic becomes easier and easier, and up-skilling into a new topic area is not too onerous.