This is Example 14.5 from Young and Freedman's University Physics on energy and momentum in SHM.
A block of mass $M$ attached to a horizontal spring with force constant $k$ is moving in SHM with amplitude $A_1$. As the block passes through its equilibrium position, a lump of putty of mass $m$ is dropped from a small height and sticks to it. Find the new amplitude and period of the motion.
The solution to the example states that during the collision the $x-$component of momentum of the block-putty system is conserved. (Why?) Just before the collision this component is the sum of $Mv_1$ (for the block) and zero (for the putty). Just after the collision the block and putty move together with speed $v_2$, so their combined $x-$component of momentum is $(M+m)v_2$. From conservation of momentum, $$Mv_1 + 0 = (M+m)v_2\; \text{so} \: v_2=\frac{M}{M+m}v_1.$$
I can't understand why the $x$-component of momentum is conserved? To have conservation of momentum during collision, there should be no external force. But here isn't gravity an external force? And clearly we don't get conservation of momentum in the $y$-component as the $y$-velocity is $0$ after collision, so how do we have conservation of momentum? I am not aware of any theorem giving conservation of momentum for only a single component. I would greatly appreciate some explanation on why this works.