Let $e$ be a continuously distributed RV with pdf $f$ and let $q( x )$ be a binary RV that depends on the former through the relation $q ( x ) = 1[h( x ) \geq e ]$, where $h$ is a well-behaved function.
Because the binary nature of $q(x)$, it holds that its first two uncentered moments are identical (this holds in fact for all higher moments): $E[q(x) \mid x] = E[q(x)^2 \mid x]$.
I am confused, however, when taking partial derivatives of these moments w.r.t. the conditioning variable $x$. For the first moment, supposing that dominated convergence holds, we have that \begin{equation} \frac{\partial}{\partial x} E[q(x) \mid x] = E[\delta(h(x) - e)\mid x] = f(h(x)), \end{equation} where $\delta$ is the Dirac delta function. For the second moment, using the chain rule, we have that \begin{equation} \frac{\partial}{\partial x} E[q(x)^2 \mid x] = E\left[2\delta(h(x) - e) 1[h(x) \geq e]\mid x\right]= 2f(h(x)). \end{equation} The partial derivatives being different seems to be at variance with the fact that both conditional moments are actually the same function. It is not clear to me, however, where I did make a mistake in the derivation of the partial derivates.