Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
You need to account for the KE when the mass is dropped and it moves downward. Unless the spring doesn't move, you can't use this energy equation. And if it doesn't move I don't think you could consider it a linear spring.