Does the potential energy change due to change in position only?
No, potential energy can also change due to shape.
For e.g. in the figure below,
Therefore, the two springs are at the same height.
Spring in figure (a) is in normal state while in figure (b) spring is in the extended state.
Potential energy stored in spring (b) is greater than in spring (a).
Consider that we two masses m1 and m2 separated by distance r. If we increase the mass m1, without changing the position of mass m2, potential energy stored in the mass m2 will increase.