Momentum is always conserved, even when there are forces, if you take into account every object interacting through forces as part of you system. The only time it will seem to be violated is if you exclude part of the system which is interacting with the system that you are considering, even if its through a long distance force like gravity. In your example the missing part of the system would be the earth, as the earth is ultimately where the momentum transfers to. But because of the mass of the earth, the velocity that it gains is very very small. Furthermore the initial force that you applied to throw the ball had made the earth move in the opposite direction at the start. So starting from that point in time, the net momentum gained by the earth will be 0. But then the initial momentum would also be 0 and so will the final momentum.
If you want to go further into the concept, the law of conservation of momentum is a direct consequence of Newton’s second law, which is that the change in momentum of an object is equal to the force applied on it, and Newton’s 3rd law, which is that every action force has an equal and opposite reaction force. You should be able to see how that leads to the conservation of momentum. If you take into account the whole system starting from the time everything was at rest before each object gains its initial momentum via forces, the total momentum of the system will always be 0.