Let us consider this picture.
$\Rightarrow$ The first picture shows the initial position of the block when the spring is in its natural length and is kept on a smooth horizontal table.
$\Rightarrow$ The second figure corresponds to the situation in which the block is pulled straight on the smooth horizontal table from its natural length (indicated by the first dashed line).
$\Rightarrow$ The third figure corresponds to the situation in which the spring is first pulled and is then turned around a hinged nail and is then brought to the same final position as it is in the second figure (indicated by the second dashed line).
The block is moved on the horizontal table only and is not pulled vertically in any of the figures.
So in picture (b) and (c) the initial and final positions of the block is same but I don't think the spring potential energy is equal in both the cases.
Surely the spring elongated more in the third case so it stores more potential energy but we also know that the potential energy is equal to the negative of the work done by conservative forces so doesn't this mean that the work done by the spring depends on the path on which the block travels?
Can someone explain what is happening here? Where am I wrong?