Suppose a mass $m$ is attached to a spring. Now if the mass is released, the tension will be the restoring force of the spring and since the mass is neither going up nor going down, we have $kx=mg$ or $x=\frac{mg}{k}$.

Now we approach it from another direction. The initial energy of the system is $0$ and the present energy of the system is $\frac{1}{2}kx^2+mg(-x)$. Here in this case $x=\frac{2mg}{k}$. Where did we go wrong then? Since the both aren't equal.