This is a well known question dealing with springs !!!!
When you lower a weight onto a spring the force exerted on the spring increases from 0 up to the maximum (the weight of the object).
Therefore the work done compressing the spring = AVERAGE force x distance
= 0.5F x distance.
During the placing of a weight on a spring your hand is part of the process and ensures that the force on the spring increases from 0 to the maximum.
On the other hand (sorry !!!!!) if you release (drop) the weight then the force on the spring is constant (mg) for the compression and the extra (0.5mgh) energy appears as KE... the mass on the spring will bounce up and down
Doc Al has said the same !!!!