Let $m_1,m_2$ have velocities $v_1,v_2$, where $v_1<v_2$ and $m_1$ is initially ahead of $m_2$.
$m_2$ has a spring attached to its front (in direction of motion).
Once $m_2$ catches up with $m_1$, the spring will be compressed between the two masses, and will (in an effort to return to its initial state) exert a force on both $m_1$ and $m_2$.
This force will cause $m_1$ to accelerate, and $m_2$ to decelerate.
Prior to the closest approach of the two masses, $v_1<v_2$. We know this because (given that the masses are going to get closer), $m_2$ must still be approaching $m_1$.
Following the closest approach of the two masses, $v_1>v_2$. We know this because, given that the masses are no longer getting closer together, and they are still accelerating and decelerating, respectively, $m_2$ must be receding from $m_1$.
Given that we know what is happening on either side of the closest approach of the masses, and we know that the velocities of the masses must change without instantaneous shift (cannot skip past the point at which their velocities are equal), the only logical conclusion is that the velocities of the two masses are equal at the closest approach.
Best Answer
$ "MAXIMUM" $ by it the author to the problem means that what is the largest compression in the spring before all the kinetic energy of the block is converted into elastic potential energy . The obvious answer to minimum compression is $ 0 $ ( the state in which the spring is in its mean position ) .You are wrong if it wasn't maximum compression then velocity of the mass wouldn't be $ 0 $ you can see it is quite obvious that the total energy of the system is shared between the E.P.E and the K.E initially it is purely kinetic in nature but there must be a moment when it is purely elastic and at that moment as. Spring 's potential energy is $ \frac {1}{2} kx² $ hence $ x $ must be maximum .