_(I recently found this older question, and found that the earlier answers were not easy to wrap my head around, and they did not add much understanding for me.   So here is my take.)_

The key part of the OP's question is: what are the left and right hand sides of this equation counting?

And the answer to that is: _the number of 'walks' of length 2_.

(This is probably not official terminology, but by 'walk' I mean a path that is directed, so $\;A \to B \to C \not= C \to B \to A\;$, allowing duplicates, e.g. $\;A \to B \to A\;$.)


Now, before trying to give a more 'calculational' proof of this equality, $%
 \newcommand{\calc}{\begin{align} \quad &}
\newcommand{\op}[1]{\\ #1 \quad & \quad \unicode{x201c}}
\newcommand{\hints}[1]{\mbox{#1} \\ \quad & \quad \phantom{\unicode{x201c}} }
\newcommand{\hint}[1]{\mbox{#1} \unicode{x201d} \\ \quad & }
\newcommand{\edge}[2]{\{#1,#2\} \in E(G)}
%$ note that the expression $$\tag{*}\sum_{\edge x y} d(x) + d(y)$$ is a potentially confusing, for two separate reasons.

First, this summation runs over all edges (and not over all ordered pairs of vertices, as $$\sum_{\substack{x,y \in V(G) \\ \edge x y}}$$ does, which visits each edge twice).  So $\Ref{*}$ really says, "sum over all $\;p \in E(G)\;$, where the unordered pair $\;p\;$ is split into its two parts $\;x\;$ and $\;y\;$, in arbitrary order.

Second, summing over unordered pairs $\;\{x,y\}\;$ only works because the expression $\;d(x)+d(y)\;$ is symmetrical in $\;x\;$ and $\;y\;$: to write for example $$\sum_{\edge x y} d(x) + 2 d(y)$$ would be meaningless.

For these reasons, I prefer to write $\Ref{*}$ as $$\tag{*'}\sum_{\substack{x,y \in V(G) \\ \edge x y}} d(x)$$ which is the same but now the summation runs over ordered vertex pairs, not edges.


With the above, the OP's equality then becomes
\renewcommand{\edge}[2]{\{#1,#2\} \in E}
\sum_x d(x)^2 = \sum_{\substack{x,y \\ \edge x y}} d(x)
$$  (Note how I leave out $\;\in V(G)\;$ throughout, and write $\;E\;$ instead of $\;E(G)\;$, to keep things readable.)  And this puts us in a position to prove $\Ref{0}$, using the definition of 'degree':
d(x) = \sum_{\substack{y \\ \edge x y}} 1

The proof is just a matter of expanding each side of $\Ref{0}$ using definition $\Ref{1}$, and then combining all summations.  For the left hand side we have
    \sum_x d(x)^2
\op=\hints{expand square; expand definition $\Ref{1}$ of $\;d(x)\;$, twice,}\hint{using different variables to prevent confusion later}
    \sum_x \left(\sum_{\substack{y \\ \edge x y}} 1\right) \cdot \left(\sum_{\substack{z \\ \edge x z}} 1\right)
\op=\hint{move $\;\cdot \sum_{\substack{z \\ \edge x z}} 1\;$ into second sum}
    \sum_x \sum_{\substack{y \\ \edge x y}} \left(1 \cdot \sum_{\substack{z \\ \edge x z}} 1\right)
\op=\hint{simplify; merge nested summations}
    \sum_{\substack{x,y,z \\ \edge x y \\ \edge x z}} 1
And for the right hand side we simply have
    \sum_{\substack{x,y \\ \edge x y}} d(x)
\op=\hint{expand definition $\Ref{1}$ of $\;d(x)\;$}
    \sum_{\substack{x,y \\ \edge x y}} \sum_{\substack{z \\ \edge x z}} 1
\op=\hint{merge nested summations}
    \sum_{\substack{x,y,z \\ \edge x y \\ \edge x z}} 1
This concludes the proof that both sides of $\Ref{0}$ are equal.


Finally, note how $\;\sum_{\substack{x,y,z \\ \edge x y \\ \edge x z}} 1\;$ indeed directly expresses that we are counting 'walks' of length 2, and the left and right hand sides of $\Ref{0}$ are counting them in two different ways.$%