As you say, momentum is conserved when there is no external resultant force acting on the system. This is a statement of Newton's 2nd law: when the net force acting on a system is zero, there is no change in momentum.
$$ \vec{F}_\mathrm{net} = \frac{d\vec{p}}{dt} $$
an example
It might help to think about an example. Lets consider the head on collision of two objects. During the collision each object applies a force to the other. Object $A$ pushes on object $B$ causing $B$'s momentum to change:
$$\Delta \vec{p}_B = \vec{F}_{A,B}\, \Delta t $$
And object $B$ pushes on object $A$ causing $A$'s momentum to change:
$$\Delta \vec{p}_A = \vec{F}_{B,A}\, \Delta t $$
Newton's 3rd law tells us that $\vec{F}_{B,A} = -\vec{F}_{A,B}$, so $\Delta\vec{p}_A = - \Delta\vec{p}_B$. We need to recognize that each force is applied for the same time interval $\Delta t$, too. The forces are applied during the collision, and both objects start and stop touching at the same times.
When we consider the whole system of both objects, the total change in momentum is zero.
$$\Delta\vec{p}_\mathrm{sys} = \Delta\vec{p}_A + \Delta\vec{p}_B = 0$$
Total momentum is conserved during the collision. Because the interaction forces ($\vec{F}_{A,B}$ and $\vec{F}_{B,A}$) are internal to the system the system doesn't have a net force.
Notice we did not care how big those forces were, nor did we care how long the collision lasted. What matters is the symmetry of the forces that comes from Newton's 3rd law.
energy
So what does this have to do with energy? The example didn't use energy at all.
Lets take our example particles to be equal mass and initially moving with equal speed in opposite directions. In order to conserve momentum the the particles must have equal and opposite velocities after the collision, but they don't necessarily have to have the same velocities as before.
If energy is lost, they will each be moving slower than before. An explosion during the collision could add energy to the system, causing them to go faster than before. Each case would still conserve momentum.
The change of momentum due to an applied force is given by the impulse of the interaction. This is true for any object in any interaction:
$$J = F\Delta t$$ During a typical collision problem, both $F$ and $\Delta t$ are small compared to the force of collision and the duration of the collision. Hence, the impulse due to gravity can be neglected.
Best Answer
There is a simple solution to your question. You must analyze what belongs to the system and what doesn't. In both cases, the ground isn't a part of the system, hence if the ground has any interactions with the system, then you may not conserve momentum. However, in the second case, the spring is a part of the system, i.e. the forces on the blocks due to springs are internal forces, whose effects don't affect the force in Newton's second law, or just that there is no net unbalanced force. Thus you may conserve momentum in the second case but not in the first case.
So here are the conclusions
Hope this helps