Derivation of random variable for chi-square distribution.

#1
Hello all,
In the chi-square distribution, how is the value of random variable derived. In the textbooks, the random variable is given directly as.

stat.png
1st equation is for random variable, 2nd value is the test statistic used during inference of variance of a population.

Source: Introduction to Statistical Quality Control by DOUGLAS C. MONTGOMERY