This is a very subtle, but important point here, so please pay attention to BRT!
Intuitively think about two identical springs. One is at zero compression and the other is at 20cm compression.
Which do you *intuitively think* would be harder to compress further? The spring at rest (zero compression) or the spring that is already slightly compressed (20cm compression)?
If you think about this, I think that you'll realize that it's gets harder to compress spring further you push it. Thus, the equations for Energy and Force, have to represent the instantaneous values for any given compression length, and do not represent general values over the entire length of the spring.
Knowing that, you should realize that the equation 1/2kx^2 gives you the energy of the spring for only one specific compression length. So, to find the difference in energy between a 10cm compression and the 50cm compression you have to find the difference between the energies at those points. Or, as BRT already showed, you subtract 1/2kx1^2 - 1/2kx2^2.