Let us assume the pipe is fixed and pipe is not moving.
Since Centre of mass is not moving , we get , v × m1 = - v2 × m2
Hence magnitude of v2 = ( v × m1 ) / m2
Let us assume the other possibility, that pipe is not fixed and moveable.
Due to smaller cross section S1 , velocity v is greater than v2 .
Hence the pipe will move towards left with speed v,
while other piston of mass m2 moves with speed v2 towards rightside.
Again to keep the centre of mass at rest in absence of external force, we have
(m1+M) v = m2 v2 or v2 = [ (m1+M) v ] / m2