Add and substract $E(Y|X)$ in your expression and condition to $X$ to prove the undebraced expression is equal to zero. \begin{align*} & E(Y - g(X))^2 = \\ &E (Y- E(Y|X))^2 + 2\underbrace{E\left[(Y - E(Y|X) (E(Y|X) - g(X))\right]}_{=0} + E(E(Y|X) - g(X))^2 \\ &\geq E(Y- E(Y|X))^2 \end{align*}
To reply to the comments in the question here is why the underbraced expression is equal to zero.
$$E\left[(Y - E(Y|X) (E(Y|X) - g(X))\right] = E \{ E\left[(Y - E(Y|X) (E(Y|X) - g(X))|X\right] \} = E \{(E(Y|X) - g(X)) \underbrace{E \left[(Y - E(Y|X) |X\right]}_{=0} \} = 0 $$ Where the term $E(E(Y|X) - g(X))$ goes out the conditional expectation to $X$ because it is a function of $X$.