If there are no dissipative forces acting on the string, than the principle of conservation of energy holds.
When the string is relaxed, it has zero elastic potential energy
If we were strech the she spring, we would increase it's potential energy. After releasing the spring, when it's relaxed again, all potential energy will have been converted into kinetic energy.
Therefore, the elastic potential energy of the stretched spring should be equal to the amount of kinetic energy when it's relaxed