For $Y\sim \operatorname{Pois}(1)$ we know that $E(X\mid Y)=\frac{Y+1}{2}$. Find $E\left(\frac{2X}{(Y+1)^2}\right)$.
In the solution they said that: $$ E\left(\frac{2X}{(Y+1)^2}\right)=E\left(E\left(\frac{2X}{(Y+1)^2}\mid Y\right)\right)=E\left(\frac{2}{(Y+1)^2}E(X\mid Y)\right) $$ I don't understand why $E\left(E\left(\frac{2X}{(Y+1)^2}\mid Y\right)\right)$ is equal to $E\left(\frac{2}{(Y+1)^2}E(X\mid Y)\right)$. What general property did they use for that?
Is it true to say that for every function $g(y)$ we get $E(g(Y)X\mid Y)=g(Y)E(X\mid Y)$?
The conditional random variable $$\frac{2X}{(Y+1)^2} \mid Y$$ is random only with respect to $X$, because $Y$ is given. Therefore, $$\operatorname{E}\left[\frac{2X}{(Y+1)^2} \mid Y\right] = \frac{2}{(Y+1)^2} \operatorname{E}[X \mid Y],$$ just as we write $$\operatorname{E}[cX] = c \operatorname{E}[X]$$ for a scalar $c$. Now take the expectation with respect to $Y$ and we get the claimed equality.