Let $X$, $Y$ be random variables in a probability space $(\Omega, \mathcal{F}, \mathbb{P})$ with $\mathbb{E}\left(X^{2}\right )<\infty$ and define the set:
$$\mathcal{N}:=\left\{g: g \text { is measurable and } \mathbb{E}\left(g(Y)^{2}\right)<\infty\right\}$$
We want to show that
$$ \inf _{g \in \mathcal{N}} \mathbb{E}\left[(X-g(Y))^{2}\right]=\mathbb{E}\left[(X-\mathbb{E}(X|Y))^{2}\right]. $$
My question is how to prove that $\mathbb{E}[(\mathbb{E}(X|Y)-g(Y))(X-\mathbb{E}(X|Y))]=0$ in this case. What I could verify is that $\mathbb{E}\left[\left(\mathbb{E}(X|Y)-g(Y)\right)\mathbb{E}\left(X-\mathbb{E}(X|Y)|Y\right)\right]=0$.
Note that $\mathbb{E}(X|Y)-g(Y)$ is $\sigma(Y)$-measurable, so by the tower property, taking out what is known, and linearity we have
\begin{align*} \mathbb{E}[(\mathbb{E}(X|Y)-g(Y))(X-\mathbb{E}(X|Y))] &= \mathbb{E}[\mathbb{E}[(\mathbb{E}(X|Y)-g(Y))(X-\mathbb{E}(X|Y))|Y]] \\ &= \mathbb{E}[(\mathbb{E}(X|Y)-g(Y))\mathbb{E}[(X-\mathbb{E}(X|Y))|Y]] \\ &= \mathbb{E}[(\mathbb{E}(X|Y)-g(Y))(\mathbb{E}[X|Y]-\mathbb{E}(X|Y))] \\ &= 0. \end{align*}