This question already has an answer here:
Write down the prime factorization of $a^2$ in terms of that for $a,$ and similarly for $b^2.$
There exists $x,y \in \mathbb{Z}$, we have $ax+by=1$. Hence,
$$a^2x^2 + b^2 y^2 + 2abxy = 1 \implies a^2X + bY = 1 \implies \gcd(a^2,b) = 1$$
Similarly, $(a,b^2) =1$. Hence, we have
$$(a,b) = 1 \implies (a^2,b) = 1 \text{ and }(a,b^2)=1$$
Since $(a^2,b) = 1$ replacing $a$ by $a^2$ in the above argument, we have
$$(a^2,b) = 1 \implies (a^4,b) = 1 \text{ and }(a^2,b^2)=1$$
And we are done.
Hint: If $p$ is a prime then $p\mid a^{2}\iff p\mid a$
Use decomposition in powers of primes. If gcd$(a,b)=1$, they have no common primes in their decomposition. Now, squaring a number doesn’t change the primes in the decomposition, just their exponent. If $$n=p_1^{a_1}p_2^{a_2}…p_k^{a_k}$$then $$n^2=p_1^{2a_1}p_2^{2a_2}…p_k^{2a_k}$$
Therefore gcd$(a,b)=1$ if and only if gcd$(a^2,b^2)=1$
Here I will use the shorthand $(x,y):=\gcd(x,y)$.
$$\begin{align}1-ax&=by\\
1-2ax+a^2x^2&=b^2y^2\\
1-2ax&=a^2(-x^2)+b^2y^2 \end{align}$$
Note that we can write $2a^2(-x^2)+(-ax)(1-2ax)=-ax$, but $(-ax,1-2ax)=1$. Since $(-a^2x^2,1-2ax)$ divides any linear combination of the two terms inside the gcd, $(-a^2x^2,1-2ax)=1$. Similarly, $$(-a^2x^2,b^2y^2)|1-2ax\Rightarrow (-a^2x^2,b^2y^2)|(1-2ax,-a^2x^2)\Rightarrow(-a^2x^2,b^2y^2)=1$$