The proof is applying your identity with $a_i:=X_i-E(X_i)$ but has an error. The identity is derived as follows:
$$\left(\sum_{i=1}^na_i\right)^2 =\left(\sum_{j=1}^na_j\right)\left(\sum_{k=1}^na_k\right)=
\sum_{j=1}^n\sum_{k=1}^na_ja_k\tag1
$$
At this point the idea is to separate out the $j=k$ case:
$$
=\sum_{i=1}^na_i^2 + \sum_{j\ne k} a_ja_k\tag2
$$
The proof writes $\sum_{j\ne k} a_ja_k$ as
$$\sum_{j=1}^n\sum_{k=1}^n a_ja_k,$$ which is incorrect. Instead the sum over $k$ should exclude $k=j$.
Another way to write the RHS of (2) is:
$$ \sum_{j\ne k} a_ja_k \stackrel{(a)}= 2\sum_{1\le j<k\le n}a_ja_k\stackrel{(b)}=2\sum_{j=1}^n\sum_{k=1}^{j-1} a_ja_k
$$
Version (a), which is proved here, leads directly to version (b), which is the form you're familiar with.