While writing the equations of motion, it is specially taken care of that the direction of the force is properly labeled as the equation depends on being arithmetically neutral. The elongation or the suppression in the spring is in a direction that is opposite to the force generated in the spring due to the elastic potential energy. Hence a negative sign is added to the equation to signify this change of direction.