The question seems a bit odd because "time of maximum spring compression" is an odd concept. The spring compression is a function of time and the time of maximum spring compression is zero because it's an instant not a time interval. Maybe the question means the time interval from the time the car first touches the spring to the time of greatest compression.
Assuming this is the case, and bearing in mind that because this is a homework question we're only allowed to give hints, the trick to doing this question is to realise that the spring behaves as a simple harmonic oscillator i.e. the compression of the spring from the moment the car touches it will be:
$$d = A sin(\alpha t)$$
where $A$ and $\alpha$ are some constants that you need to calculate. The problem simplifies a lot if you think about the relation between the period of a harmonic oscillator and the amplitude of oscillation.
I am just repeating what everyone has said here, but hopefully this will make it clearer.
What you are doing is conflating $x$ as a coordinate and as a distance. When we use Newton's laws $F = m \ddot{x}$, $x$ is a coordinate.
Let's set up the scenario more carefully than you have done. Let's have a coordinate system where rightwards is positive. Say we have a spring of unstretched length $l$ (this is a distance, not a coordinate). Fix one end of the spring be at coordinate $0$, and let the free end be at coordinate $l$ initially.
Now we consider perturbations about this equilibrium configuration. Define $x$ to be the displacement of the free end from coordinate $l$, so that the coordinate of the free end is now given by $y = l + x$ (it is a function of time). Note that $x$ is not the extension amount. The extension amount is instead $|x|$.
Now we can do what you did, consider the two cases. When the spring is extended, that is, when $x > 0$, we have from Newton's 2nd law:
\begin{align}
m \ddot{y} = -k|x|.
\end{align}
Ok let's pause to see what I've written here. the LHS is the 2nd time derivative of the coordinate of the free end of the spring (with a mass attached to it). The right hand side is the sum of forces, which by Hooke's law has magnitude $k|x|$ and I have thrown in the minus sign because it points to the left.
But note that $\ddot{y} = \ddot{(l + x)} = \ddot{x}$ since $l$ is a constant. Also, since $x > 0$, $|x| = x$. So we get
\begin{align}
m\ddot{x} = -kx.
\end{align}
When the spring is compressed, $x < 0$. So
\begin{align}
m\ddot{y} = k|x|.
\end{align}
the LHS is exactly the same as before, and the RHS has now a positive sign because the force points to the right. But $x < 0$ means that $|x| = -x$, so we get
\begin{align}
m\ddot{x} = -kx,
\end{align}
exactly the same as before.
So there is no trouble.
Now you might protest and say, hey I want to define $x$ to be the distance of the free end from the equilibrium length, so $x \geq 0$, instead of as the displacement. Then what changes is this:
the coordinate is now a piecewise function. If the spring is stretched, $y = l + x$; if it is compressed, $y = l-x$.
For the stretched case, writing Newton's law gives
\begin{align}
m \ddot{y} = m\ddot{x} = -kx.
\end{align}
For the compressed case,
\begin{align}
m \ddot{y} = -m \ddot{x} = kx \implies m\ddot{x} = -kx.
\end{align}
Once again, we get back the same equations, and there is no problem.
Best Answer
When the spring reaches maximum compression, the mass is instantaneously at rest but it is not in static equilibrium. The net force on it is not zero : $kx \ne mg$. Like a pendulum at the end of each swing, there is a net force on the mass causing it to accelerate towards the equilibrium position - at which the net force on it is then (for an instant) zero. Your calculation is correct. It is your interpretaion of the result which is at fault.
At the lowest point the compression force in the spring is $kx=2mg$, acting upwards on the mass, while gravity is still pulling down with force $mg$. There is a net force of $mg$ acting upwards.