How can I prove such statement?
I think that if $x|y^2$ then $x|(y*y)$ so $x|y$ or $x|y$ which means that in any case $x|y$. Am I correct?
I ask this question as such template because I think that it doesn't matter which $x$ or $y$ represents.
However, the original question is: if $6|n^2$ then $6|n$ and if $12|n^2$ then $12|n$.
False. $4|36$ but $4\!\! \not|\, 6$. You should require $x$ to be a prime number (or a product of distinct primes). $x=6$ will work, $x = 12$ won't.