You can see this as the expectation being unbiased conditional on $x$, in which case the $d_i$ can be considered constants.
(and since the conditional expectation is zero, so will be the unconditional expectation)
The derivation in your question is only correct for constant $x$.
But it happens to be the same result for variable $x$, because the expectation conditional on $x$ is zero independent of it's value. (but for this extra step, from constant to conditional, the derivation is indeed not complete)
See here an intuitive plot how the marginal distribution of $y$ can be considered as a sum of the distributions of $y$ conditional on $x_1$.

The data here has been generated according to some silly/fancy model:
$$\begin{array}{} x_1 &\sim& N(\mu = 10, \sigma = 1) \\ y \vert x_1 &\sim & N(\mu = 0, \sigma = 2+ \sin(5x_1)) \end{array}$$
You can consider the distribution of $y$ as a sum of the distributions/components of $y$ conditional on $x$. When each of these components has a mean equal to zero, then the sum of them will also be zero.
### settings for layout and computation set.seed(1) layout(matrix(1:2,1), widths = c(2,1)) par(mar= c(4,4,2,1), mgp = c(2.5,0.8,0)) ### generate data x <- rnorm(10^4,10,1) y <- rnorm(10^4,0,2+sin(x*5)) ### conditional colouring col <- hsv(x/14,1,1,0.1) ### scatterplot plot(x,y, col = col, bg = col, pch = 21, cex = 0.7, ylim = c(-10,10), main = "scatter plot \n", cex.main = 1, xlab = expression(x[1])) ### density plots for different conditions x plot(-100,-100, ylim = c(-10,10), xlim = c(0,220), xlab = "", ylab = "", main = "conditional \n distribution", cex.main = 1) for (xs in seq(7,13,0.4)) { sel = ((x>xs-0.2)*(x<xs+0.2)) h <- hist(y[sel==1], breaks = seq(-15,15,0.4), plot = FALSE) lines(h$counts,h$mids, col = hsv(xs/14,1,1,0.5), lwd = 2) }