I think this is a simple enough question but I am not able to see the consistency in two different math of the same problem. Here is the problem,
One has to determine the compression of the spring. $h'$ in the figure is the final height of the top of the spring after the mass has come to rest and $h$ is the initial height. So I applied the conservation of energy equation by saying that,$$mg(H+h) = mgh'+\frac{1}{2}k(h-h')^2$$ This can be rearranged to get, $$\frac{1}{2}k(h-h')^2-mg(h-h')-mgH=0$$ which is a quadratic equation in the compression term $(h-h')$ and can be solved easily with quadratic formula. But what if you used Hooke's law to determine the compression? In which case, $$F=W=k(h-h')$$ and then $$(h-h')=\frac{mg}{k}$$ which will give a different answer. If these two ways were consistent then substituting the later relation in the former energy equation, should give an identity but it does not.
I am missing some very obvious piece of the puzzle here but I can't figure out what that piece is.