Proof. We will prove the contrapositive. Suppose $d\nmid a$. By the division algorithm, $a = qd + r$ for some $q\geq 0 $ and $0<r<\lvert d \rvert$. Then, $a^{2} = (qd + r)^{2} = q^{2}d^{2} + 2qdr + r^{2} = d^{2}(q^{2} + \frac{2qr}{d}) + r^{2}$. Since $r < \lvert d \rvert$ ,$r^{2}< d^{2}$. Thus, there is a nonzero remainder, so $d^{2}\nmid a^{2}$. Hence if $d^{2}\mid a^{2}$, $d\mid a$.
$\square$
Why use contrapositive argument... This is much easier proved directly, no?
We know $d^2 | a^2$ (which on a side note means $d \ne 0$)
$$\Rightarrow a^2 = d^2.q$$
for some integer $q$
But then $q = (a/d)^2$ so $q$ is a perfect square of a rational number.
Now let's assume $(a/d) = (a_1/d_1)$ where $a_1$ and $d_1$ are coprime.
$q = (a_1/d_1)^2$
$q d_1^2= a_1^2$
$\Rightarrow d_1/d_1$ and $d_1 / a_1^2$ but these two $d_1$ and $a_1^2$ are also coprime.
So the only way this to happen is if $d_1 = 1$ or $d_1 = -1$
And this means the rational $a/d$ is also an integer.
But $q$ is also an integer.
So $q = m^2$ where $m=a/d$ is also an integer.
Then we get: $a^2 = d^2.m^2$
and then: $|a| = |d|.|m|$ This means $|d|$ divides $|a|$ and so $d$ divides $a$.