When a moving object contacts a stationary object with a spring, why is the spring compression maximum when two objects have the same speed

When a moving object contacts a stationary object with a spring, why is the spring compression maximum when two objects have the same speed

Ignore the people upstairs
Maximum spring compression = minimum distance
In this problem, the distance between the two decreases first and then increases. The turning point of increase and decrease is when the speed of the two is the same
So at the same speed, the distance is the smallest