Despite the fact that only one person pulls on the rope, both trolleys come closer to each other. That’s the manifestation of the Newton’s third law of dynamics: when you act on the other trolley-person system with a force of given value, a force of the same value but opposite direction acts also on you. When the non-moving trolley is hit by the moving one, it takes over the moving trolley’s momentum and drives away, while the hitting trolley stops. It’s an example of elastic collision. If the trolleys got stuck with each other, a nonelastic collision would occur.