Though the proof of this is done in a previous question, I have some doubt about a certain concept. So I ask to clarify it.
In the proof we say that $\sqrt{p} = \frac{a}{b}$ (In their lowest form). Now $$p = a^2 / b^2\\p\cdot b^2 = a^2.$$
Hence $p$ divides $a^2$ so $p$ divides $a$. We say that the above mentioned condition ("Hence $p$ divides $a^2$ so $p$ divides $a$") is valid as $p$ is a prime number. I didn't get the fact that why this is only true for prime numbers. Could someone please me this?
The square root of a positive integer $n$ is either a positive integer or irrational. To see this, suppose $n=\left(\frac pq\right)^2$ where $p,q\in\mathbb Z$, $p,q>0$, and $\gcd(p,q)=1$. Then $p\nmid q$, and $q\nmid p$, so $p^2\nmid q^2$ and $q^2\nmid p^2$ (this is easy to see from the prime factorizations). This implies that $\left(\frac pq\right)^2$ is not an integer, a contradiction.
(And clearly a prime number does not have an integer as a square root.)