Let $D$ and $Z$ be two random variables, where $D$ is binary. Let $P(Z) = \mathbb{P}(D=1|Z)$.
\begin{split} \mathbb{P}[D=1 | P(Z) = u] &= \mathbb{E}[\mathbb{P}[D=1 | Z, P(Z) = u] | P(Z)=u]\\ &= \mathbb{E}[\mathbb{P}[D=1 | Z] | P(Z)=u]\\ &= \mathbb{E}[P(Z) | P(Z)=u]\\ &= u \end{split}
I understand that the first equality follows from law of iterated expectations. My question is that in this proof, in the second equality, why are we able to remove the inner conditional of $P(Z)=u$?
Is the reason that $P(Z)$ is a function of $Z$ and we can drop any expression that involves functions that take only $Z$ as argument, when $Z$ is included in the conditional?