P→ compressed state of string
Q→ natural length of spring
From P to Q
aB=KxmB
aCM=mBaBmA+mB=(mB)(Kx)mA+mB
From P to Q, compression x decreases. Therefore, aCM decreases. After Q, A leaves contact with wall, spring comes in its natural length. Net force on system becomes zero.
Therefore, aCM become zero.
From P to Q velocity of B, therefore velocity of COM will increase. After that aCM becomes zero.
Therefore, vCM becomes constant.