Say I wanted to take the following expectation for $C$ a constant and an RV $\theta$ with density $p(\theta)$.
$$E[\theta-C] = \int_{\theta}(\theta-C)p(\theta)d\theta$$
Now given $p(y|\theta)$ and a function $\phi(y)$, I would like to take the following expectation:
$$E[\theta-\phi(y)]$$
I am having trouble proving to myself the following:
$$E[\theta-\phi(y)] \ne \int_{\theta}(\theta-\phi(y))p(\theta)d\theta$$
But rather I believe the correct solution is:
$$E[\theta-\phi(y)] = \int_{y}\int_{\theta}(\theta-\phi(y))p(\theta|y)d\theta\ p(y)dy$$ $$=\int_{\theta}\int_{y}(\theta-\phi(y))\ p(\theta,y)dyd\theta$$ $$=E[E[(\theta-\phi(Y))|Y]]$$
Intuitively, I think the last line makes since, taking the average of $\theta -\phi(y)$ for a given $y$, and then taking the average of that over all $y$.
But I am still not convinced on why I shouldnt take the expectation treating $\phi(y)$ as a constant.
Is it necessary or sufficient to do the iterated expection if $Y$ is a random variable? Or is it only necessary when $Y$ depends on $\theta$ via $p(y|\theta)$?
Thanks for reading and any help on clairification!