Here is the theory.

If are independent, standard normal random variables then the sum of their squares will follow chi-square distribution with k degrees of freedom.

A random variable can be standardised. Since we have then we also have

which are standard normal random variables and the sum of their square will follow chi-square distribution. It follows from this that ~; and

A bit of algebra and you get