If the kinetic energy of both the ball decreases, how can their
velocities be equal?? The front one ( B ),from the beginning, had low KE; if
it decreases during the deformation, how can its velocity be equal to
the velocity of the rear ball ( A )?
In order to get a clear picture, let's consider the extreme case when the velocity of B = 0
Let's make a concrete example with numbers $m_A = 1, m_B = 2, M = 3$:
Suppose that:
$v_a = 6m/s$ and $v_b, p, E_k = 0 \rightarrow E_k = 0.5 * 6^2 = 18, p = 1 * 6 = 6, v_{cm} = p/M = 2$
Kinetic energy and momentum are conserved only in elastic collisions, but if the bodies stick together the collision is inelastic an only momentum is conserved:
After the collision velocity of A would be anyway lower as KE should be distributed among more mass, but some KE is lost in the crash. How much?
Momentum is conserved: $ p_{ab} = 6$ , from this datum you can calculate its velocity which now coincides with the velocity of center of mass:
$$v_{ab} = v_{cm}= \frac{6}{3} = 2$$ and $E_{AB} = 0.5 * 2^2 *3 = 6 \rightarrow E_A = 2 + E_B = 4$.
Some energy has been transferred to B (4 J), but two thirds of the kinetic energy(12 J) have been changed to other forms of energy. The general law of 'conservation of energy' has not been, anyway, violated
Velocity of center of mass is the same, although KE has changed. Note that momentum is conserved because we are assuming that on the surface of contact there is no friction.
I hope your main question has got an answer by now, velocities can and must be equal because AB is now one single body: the rear ball has decreased and the front ball has increased its v and the two values level out.
(This is not due to the loss of KE, even if it had been conserved the two bodies would have levelled their v to 3.464, but this would violate the principle of conservation of momentum that would have increased to 10.4)
As to the queries in your comments: when the bodies have reached the maximum deformation they will move at final and same v. It is impossible to determine how much of the amount of KE lost and transformed will be absorbed by each body, as this depends on the material they are made of: the more a body is deformable the more energy it will absorb
.. But what about the case when the front ball is moving?
It makes no difference! Just think of communicating vessels, once two bodies are joined and become a single body... energy, velocity and momentum level out and are unified.