The full force is not applied for the full distance.
In the simple case of a constant force over a fixed distance you can just multiply force by distance. But in the case of a spring being compressed, the force is not constant.
You could approximate the answer by analyzing the situation in small steps... You compress the spring the first 1/10th of the distance using 1/10th of the full force, the next 1/10th of the instance using 2/10th of the total force and so on. This approach would give you an answer that is pretty close.
An exact answer can be obtained by using calculus and integrating instantaneous force over incremental distance. That answer turns out to be 1/2 * distance * maximum-force