Can't figure out my mistake in solving the problem of spring hanged from the ceiling and a weight attached at its end [closed]

A spring with the length $$50cm$$ and $$k=400\frac Nm$$ is hanged from the ceiling. Then we attach a weight with the mass $$m$$ at the end of the spring and while the spring has its normal length, we release the weight. If maximum length that spring reach be $$55cm$$, what is the mass of $$m$$?

Here is the diagram of the problem,

The solution provided for this problem is based on the fact that the energy of the spring is equal to energy of the acceleration of gravity ($$U_e=U_g$$),

$$U_e=\frac12 k \Delta x^2=\frac12\times400\times(\frac1{20})^2=\frac12$$ $$U_g=mgh=m\times10\times5\times10^{-2}=\frac m2$$Hence $$m=1kg$$.

But my problem is, why we can't say the force $$W=mg$$ cause the length of the spring be increased by $$5cm$$ and use $$F=k\Delta x$$? By doing it, I got $$10m=400\times \frac1{20}$$ and $$m=2kg$$. I'm wondering what is the mistake with my approach.

Yes, it is the force $$F=mg$$ that causes the length of the spring to elongate, however, the condition $$F=k\Delta x$$ gives you the elongation $$\Delta x$$ of the spring at which the upward force from the spring on the mass and the downward force of gravity on the mass are equal, i.e., the mass is in equilibrium. This is different from the maximum elongation that the spring will undergo! The reason being that by the time the mass reaches the equilibrium position, it will have gained kinetic energy so it will keep going downward. Thus, the maximum elongation will correspond to a situation where the mass has no kinetic energy and all of the loss of its gravitational potential energy has been converted to the spring potential energy, i.e., $$\frac{1}{2}k\Delta x^2=mg\Delta x$$.
Alternative approach (if you are interested) is to note that in simple harmonic motion the mass will be in equilibrium at the mid-point of the motion, when the extension is $$x=2.5$$ cm. At this point, the force exerted by the spring equals the weight of the mass, so
$$mg=kx \displaystyle \Rightarrow m = \frac {kx}{g} = \frac {400 \times 0.025}{10} = 1$$ N