Work done by electric force is $W=qE.x$ as electric force is constant.

But F(external) on spring mas system is equal to kx. So $W=kx.x=k{x}^{2}$ (equation 1) as external force i.e, electric force is constant.

We know that work done is stored in the form of potential energy and we know that potential energy stored in the spring is $1/2k{x}^{2}$.

So $W=1/2k{x}^{2}$ (let it be equation 2)

But the above 2 equations are not equal. From where did the 1/2 come from in the 2nd equation?