A door that won't latch is usually a strike plate alignment issue. The latch bolt and the strike plate hole are not lined up correctly.
Close the door slowly and watch where the latch bolt hits the strike plate. Rub lipstick or pencil on the end of the latch bolt and close the door firmly — this marks exactly where the bolt is making contact.
Loosen the strike plate screws and shift the plate in the direction needed until the hole aligns with where the latch is hitting. Tighten and test.
If the plate needs to move more than the existing screw holes allow, use a chisel to extend the mortise in the door jamb. Work carefully in small amounts. Fill old screw holes with toothpicks dipped in wood glue for the new screw position.