I know there is a relation between the $\gcd (x, y)$ and $\operatorname{lcm} (x, y)$ like this: $$ \operatorname{lcm} (x, y) \gcd (x, y) = xy. $$ E.g: $x = 588$ and $y = 616$
$588 = 2 ^ 2 \cdot 3 \cdot 7 ^ 2$
$616 = 2 ^ 3 \cdot 7 \cdot 11$
$\gcd (x, y) = 2 ^ 2 \cdot 7 = 28$
$\operatorname{lcm} (x, y) = 2 ^ 3 \cdot 3 \cdot 7 ^ 2 \cdot 11 = 12936$
In this case $\gcd (x, y) ^ 2$ is not equal to $\operatorname{lcm} (x, y)$
So how can I find the prime factors of $x$ and $y$ if $\operatorname{lcm} (x, y) = \gcd (x, y) ^ 2$?
Let $p$ be a prime dividing $x$. If $p$ doesn't divide $y$, then $p$ divides $\DeclareMathOperator{\lcm}{lcm}\lcm(x,y)$, but not $\gcd(x,y)$, which is a contradiction. Similarly, each prime divisor of $y$ also divides $x$.
Hence $x=p_1^{m_1}p_2^{m_2}\dotsm p_k^{m_k}$ and $y=p_1^{n_1}p_2^{n_2}\dotsm p_k^{n_k}$, where $m_i\ge1$ and $n_i\ge 1$, with $p_1,\dots,p_k$ distinct primes ($k$ could be $0$, in which case $x=y=1$).
Note that \begin{align} \gcd(x,y)&=p_1^{\min(m_1,n_1)}p_2^{\min(m_2,n_2)}\dotsm p_k^{\min(m_k,n_k)} \\[4px] \lcm(x,y)&=p_1^{\max(m_1,n_1)}p_2^{\max(m_2,n_2)}\dotsm p_k^{\max(m_k,n_k)} \end{align} so for each $i$ we must have $$ \max(m_i,n_i)=2\min(m_i,n_i) $$ and that's all.
You get all numbers with this property with the following recipe. Take $p_1,\dots,p_r,q_1,\dots,q_s$ arbitrary pairwise distinct primes (it can even be $r=0$ or $s=0$; an empty product is, by definition, $1$). Take $a_1,\dots,a_r,b_1,\dots,b_s$ arbitrary integers $\ge1$. If $$ A=p_1^{a_1}\dotsm p_r^{a_r} \qquad B=q_1^{b_1}\dotsm q_s^{b_s} $$ then $x=A^2B$ and $y=AB^2$ are numbers such that $\lcm(x,y)=\gcd(x,y)^2$. Note also that any two numbers $x$ and $y$ with this property are of this form.