I'm having a hard time trying to understand why in the below expression the product of the terms is gone and only the squared terms is left inside the summation. 
The image is taken from a pdf file about Likelihood Ratio tests (here, page 4). The same approach is found on many other sources including my professor's, but I haven't found an exhaustive explanation.
It is just some algebra with the mixed terms using that
$$\sum_{i=1}^n(X_i - \bar X)(\bar X - \mu_0) = \sum_{i=1}^n(X_i\bar X - \mu_0X_i-\bar X^2 + \mu_0\bar X)$$ $$= n\bar X\bar X - \mu_0 n \bar X - n\bar X^2 + n\mu_0\bar X = 0$$
So, all mixed terms cancel each other.