How is that $E[g(Y)X]=E[g(Y)E(X\mid Y)]$? I came across this definition of conditional expected value:
For a σ-algebra $\mathcal{G}$, $E[X\mid \mathcal{G}]$ is defined to be the random variable that
satisfies:
(i)$E[X\mid \mathcal{G}]$ is $\mathcal{G}$-measurable.
(ii)$E[\mathbb{1}_CX]=E[\mathbb{1}_CE(X\mid \mathcal{G})]$ for all $C\in\mathcal{G}$
I don't get this equality, can someone explain?

You just need to think of $X$ as a measurable function from $(\Omega,\mathcal{F})$ to $\mathbb{R}$. Now, given a coarser $\sigma$-algebra $\mathcal{G}$ on $\Omega$, with respect to which $X$ might not be measurable, our goal is to find a measurable function $Y$ (with respect to $\mathcal{G}$) that resembles $X$. It's natural, then, to ask for $Y$ to "behave" the same way as $X$ at least in the eyes of the coarser one of the two $\sigma$-algebras, which is $\mathcal{G}$. That is, we want
$$\int_{A}XdP=\int_{A}YdP$$
to hold true for $A\in\mathcal{G}$. This is just a rewrite of
$$\mathbb{E}\left(1_{A}X\right)=\mathbb{E}\left(1_{A}Y\right),\text{ for }A\in\mathcal{G}.$$
