Normally, we take $p \neq q$ so that they are relatively prime.
Notice you have $(y')^2 \cong y^2 \cong x \pmod{n}$. But this means
$$ (y'-y)(y'+y) \cong (y')^2 - y^2 \cong x - x \cong 0 \pmod{n}. $$
So $y'-y$ is a factor of a multiple of $n$, call it $kn$. If you are a little lucky, the $\gcd(|y'-y|,n)$ gives a nontrivial factor of $n$. If you are unlucky, $y'-y$ only divides $k$, giving no information about $n$. (Of course, one might try the other factor above, $y'+y$, in the unlucky case.)
Note that $y$ and $y'$ are in the interval $[1,n-1]$, so $y' - y$ is in the interval $[1-(n-1), (n-1)-1] = [2-n,n-2]$, so can never be as large as $n$. The factors of $n$ are $\{1,p,q,n\}$, and the $\gcd$ can only give you $1, p, q$ (because as just observed, it cannot give you $n$). The nontrivial factors are $p$ and $q$. So if you've been a little lucky, your $\gcd$ gave you $p$ or $q$.
Say $\gcd(|y'-y|,n) = p$, then $p$ divides $y'-y$ and $y'-y \cong 0 \pmod{p}$. Since $p$ and $q$ are relatively prime, $y' - y \not\cong 0 \pmod{q}$. The same two sentences hold with $p$ and $q$ swapped.