How to expand equation inside the L2-norm?
The FOIL rule with column vectors $u, v \in \mathbb R^n$ tells us that \begin{align} \|u - v\|^2 &= (u - v)^T (u - v) \\ &= u^T u - u^T v - v^T u + v^T v\\ &= \|u\|^2 - 2 u^T v + \|v\|^2. \end{align} (In the last step, we used the fact that $u^Tv = v^Tu = \sum_{i=1}^n u_iv_i$.)
Applying this to our particular problem, we find that \begin{align} \|Y - X \beta \|^2 &= \|Y\|^2 - 2 Y^T X \beta + \| X \beta \|^2. \end{align}
If we'd like, we could rewrite the final term as \begin{align*} \|X \beta \|^2 &= (X \beta)^T (X \beta) \\ &= \beta^T X^T X \beta. \end{align*}