Using the first law of Newton:
There is no external force on the system of two bodies : gun and bullet. So the center of mass of the two together remains at rest, means stays at the same position.
Initially, let the center of mass of gun and bullet be at position (x = 0, y = 0). Let the center of mass of gun be at (x =- Gx, y = -Gy). Let the center of mass of bullet be at position (x = +Bx, y= +By). So:
-M Gx + m Bx = 0 and -M Gy + m By = 0
Using the second law, we get there is no external force, so the total momentum remains same at all times. The center of the mass moves with velocity equal to the total momentum of the system / total mass of the system.
M v + m V = 0 v = velocity of gun = v = - m V / M
If bullet moves with velocity V, its center of mass moves with V and with a velocity V cos θ in horizontal direction. Then the gun moves backwards with a velocity of -v cos θ = - m V cos θ / M. After some time t, the positions of center of masses will be at x = -v cos θ * t and x = V cos θ * t respectively.
The center of mass of system will be at
x = [- M v t Cos θ + m V t Cos θ ] / (m+M)
= [ - M (m V Cos θ / M) t + m V t Cos θ ] / (m+M)
The center of mass remains at the same position in the horizontal direction.
If you see the vertical direction, there are forces: the normal reaction of the table on the gun, there is weight of the gun, and weight of the bullet. Initially there are force on bullet by the spring in the gun and recoil force of bullet on the gun.
The total force on gun will be zero as the normal reaction balances the other forces. When bullet is traveling in air, there is an unbalanced force = weight of the bullet pulling it down. So the center of the mass of the system of gun and bullet goes up and comes back to zero.