Well, we will hav that neither "k" or "x" are negative, the negative sign is external to both values and the reason is that this is written in that way to represent the "direction" of the movement of the system. Form example, when the spring is extended then it will represent that it will pull back, and when it is compacted it represents that it will pull outwards.

It is simply a technicallity.