The claim is that $$(n-1)S^2/\sigma^2$$ is chi squared distributed with degrees of freedom $n-1$.
$(n-1)S^2/\sigma^2$ can be written as $$\sum_i^n \left(\frac {x_i-\mu}{\sigma}\right)^2-\left(\frac {\bar x-\mu}{\sigma/\sqrt n}\right)^2$$
I am almost there with understanding why this is $\chi^2_{n-1}$ distributed. I understand that each of these individual elements is $N(0,1)$ distributed, and that a sum of $n$ $N(0,1)$ distributed variables is $\chi^2_{n}$ distributed.
But my problem is, that the distribution of $\bar x$ is not independent of the $x_i$. How do we take this fact into account to derive the desired conclusion?
Note that the existing answers I've found did not specifically address that question.
EDIT: Note that I am not asking for an explanation of why we write $n-1$ rather than $n$. I am asking specifically how we can rigorously derive that it has the distribution that it has.
EDIT 2: Those who have marked this question as a duplicate of this one may be misunderstanding my question. I am not asking for an explanation of why the degrees of freedom are $n-1$ rather than $n$. I am asking for a derivation that it is chi squared in the first place, and that it has $n-1$ degrees of freedom. My problem is clear from the question: How do we take the dependency with $\bar x$ into account? I'm not asking for an intuitive explanation of why it has $n-1$ df rather than $n$.