The leaf hangs from the hinges, not from the lock
A door leaf is held by two or three hinges, and each hinge is a pin turning inside a knuckle. Every single swing wears a little metal off the pin and the inside of the knuckle, and after a few thousand cycles the pin is a millimetre or two thinner than it was. A millimetre does not sound like much, but the leaf hangs off those pins: the far edge — where the lock is — drops by roughly the same amount, and the bolt that used to slide into the middle of the hole now arrives at the top edge of it.
Which is why the test is not "does the bolt spring back", it is "does lifting the door make it close". Lift the handle side as you swing it shut. If the door then latches, the bolt, the spring, the strike plate and the lock body are all working perfectly, and the only thing wrong is that the leaf is hanging two millimetres low. Tighten every hinge screw first — most "dropped" doors are a loose top screw, because the top hinge carries the most load. If the screws spin without gripping, the wood is stripped and the hinge needs longer screws or a shim behind it.
A latch almost never fails. The bolt is a solid metal piece and the spring is inside a steel case; there is nothing in normal use that wears them out. What does slow one down is grit — plaster dust, paint, sand from a renovation — packed into the guide slot the bolt slides in, and you feel that immediately: the bolt goes in with a scrape and comes back slowly rather than snapping.
The third case, and why it is not the lock either
Bolt snaps back crisply, the door does not need lifting, and yet it will not shut without a push — or it shuts but rattles. That is the strike plate: the bolt is arriving at the right height but not at the right depth, so it rides up the face of the plate and will not drop into the hole. The plate is held by two screws and its hole is deliberately a little oversized, so it can be moved a millimetre in any direction once the screws are slackened. Mark where the bolt rubs with a pencil or a smear of chalk on the bolt tip, close the door, and read the mark off the plate.
If the plate will not move far enough, the hole can be filed out on the side the bolt is hitting — a few strokes at a time, testing between, because a hole filed too wide lets the door rattle for ever. And if the whole leaf is visibly out of square, with the gap wide at the top on one side and tight at the bottom, that is a frame or a wall problem rather than a hardware problem, and it is worth having someone look at it before the door is planed or the hinges are packed.