Both values of $x$ are correct, but correspond to two different situations.
Suppose first that the mass is at rest. The acceleration $a$ is then zero. The sum of the forces on the mass is $F = -kx_1 - mg$. From $F = ma = 0$ one has $-kx_1 - mg = 0$, giving $x_1=-mg/k$ for the displacement of the mass from the equilibrium position of end of the spring. (Equilibrium meaning no force on the spring.)
Now suppose that the mass is released from rest at the equilibrium position of the end of the spring, which we will take to be the zero of our coordinate system. The initial potential energy of the spring is zero, the initial kinetic energy of the mass is zero, and from our definition of the origin, the initial gravitational potential energy of the mass is zero. The total energy of the system $E$ is then zero, and will remain so as the system evolves in time. After its release, the mass will fall, compressing the spring. At some point, call it $x_2$, the compression of the spring will be maximal, and the mass will stop falling. At this instant, its velocity will be zero, and so too the kinetic energy. The potential energy of the spring is $kx_2^2/2$, and the gravitational potential energy is $mgx_2$. The total energy is zero, so $E = kx_2^2/2 + mgx_2 = 0$. Solving for the maximal displacement, one obtains $x_2=-2mg/k$.
In both cases $x$ is negative, meaning that the spring is compressed. The compression is greater when the mass is allowed to fall.