If $a_1^2 ≡ a_2^2 \pmod p$, then $p$ divides $a_1^2−a_2^2$, so $p$ divides the product $(a_1 − a_2)(a_1 + a_2)$.
I read in a chapter related to quadratic residues and nonresidues that
unique prime factorization now tells us that $p$ divides $a_1 − a_2$ or $p$ divides $a_1 + a_2$, and so either $a_1 ≡ a_2 \pmod p$ or $a_1 ≡ −a_2 \pmod p$.
Why? It could be the case where both $p$ divides $a_1 − a_2$ and $p$ divides $a_1 + a_2$.