Elastic type potential exists for the system in equilibrium. If you have a potential function $U(x)$, you can always write down its Taylor series around the equilibrium point $x_0$ as
$$U(x) = U(x_0) + U'(x_0)(x-x_0) + \frac{1}{2}U''(x_0)(x-x_0)^2 + ... $$
Since the system is in equilibrium at $x_0$, so the net force $F=-U'(x_0)=0$. If we only consider the local region around the equilibrium point and set $x_0=0$, then the result is
$$U(x) = \frac{1}{2}k x^2 + K $$
where $K=U(x_0)$ and $k=U''(x_0)$.
You might argue that it is only approximation, but in reality, we always focus on a small region and wont consider large $x$ because the system is not isolated anymore. Also mathematically this expression becomes true if you take the limit of $x\to 0$.
Spring push objects away when compressed and pull them together when stretched. Therefore, it creates a potential energy function with a minimum and so the elastic potential for Hookes law follows. Note that when you stretch the spring heavily, it starts to distort and the potential is not quadratic anymore as we discussed above.