Hint $\ $ If $\: (z/a)^2 = n\:$ then $\,z/a\,$ is a root of $\:x^2 - n\:$ so $\:z/a\in \Bbb Z\:$ by the rational root test (RRT). Domains satisfying the monic case of the RRT are called integrally-closed. They are a much wider class of domains than UFDs. For example, the usual proof of RRT uses only gcds, so any gcd domain is integrally-closed.
Or by $\,(a^2,z^2)=(a,z)^2$ [see here or here], cancelling the gcd $\, (a,z)\,$ twice from $\,z^2/a^2\,$ reduces to the coprime case $(a^2,z^2)\! =\! 1,\,$ so $\,a^2\,|\,z^2\Rightarrow a^2 = \pm 1\Rightarrow a = \pm 1,\,$ so $\,a\mid z$.
If you desire to learn more about this specific property then try searching on root-closed domains. A domain D is called $n$ root-closed if for every fraction $x$ over D we have $\,x^n\in{\rm D}\Rightarrow x\in\rm D.\,$ If this holds for all $\,n\in \Bbb N\,$ then one calls D root-closed. One interesting result using this property is the following (which applies to rings of algebraic integers).
D is a Dedekind domain with torsion class-group $\iff$ D is root-closed and for every $\,\{a,b,\ldots\}\subset\rm D\,$ there is an $\,n\in\Bbb N\,$ such that the ideal $(a^n,b^n,\ldots)\,$ is principal. Domains that satisfy the latter ideal-theoretic property are sometimes called almost-PIDs or API domains.