Here's an outline of the basic ideas:
The same critical value, $C$, applies whether $H_0$ is true or $H_1$ is true.
$C=\mu_0+\sigma Z_{1-\alpha/2}/\sqrt{n}$
$C=\mu_1+\sigma Z_\beta/\sqrt{n}$
$\mu_0+\sigma Z_{1-\alpha/2}/\sqrt{n}=\mu_1+\sigma Z_\beta/\sqrt{n}$
$(\mu_1-\mu_0)/(\sigma/\sqrt{n}) = (Z_{1-\alpha/2}- Z_\beta)$
$[(\mu_1-\mu_0)/\sigma]\sqrt{n} = (Z_{1-\alpha/2}+ Z_{1-\beta})$
$\sqrt{n} = (Z_{1-\alpha/2}+ Z_{1-\beta})/[(\mu_1-\mu_0)/\sigma]$
and then you just square both sides
$n = (Z_{1-\alpha/2}+ Z_{1-\beta})^2/[(\mu_1-\mu_0)^2/\sigma^2]$
$\quad = (Z_{1-\alpha/2}+ Z_{1-\beta})/\delta^2$
Note: (1) Here I'm doing just the case $\mu_1>\mu_0$. To cover both possibilities, we really need $|\mu_1-\mu_0|$ where I have $(\mu_1-\mu_0)$; the outcome is the same.
$\quad\quad$(2) This ignores a small piece of area to the far left of the second diagram.
$\quad\quad\quad\,\,\,$When $\delta$ is large, this is negligible.