why when we stretch a string we have to do the work against the restoring force then why the work gets store in the form of potential energy in the spring?
If you pull on a spring and stretch it, then you do work. That is because you are applying a force over a displacement. Since work is the transfer of energy, we must account for to what the energy was transferred. We say that the energy was transferred into the spring. The work becomes stored energy in the spring. The work becomes potential energy in the spring.
A spring can be stretched or compressed. The same mathematics holds for stretching as for compressing springs.