The latch won't line up if the door isn't straight.
When your door doesn't latch, the problem may not be with the latch itself. While it is possible it isn't functioning properly or is out of alignment, it's also possible that the door hinges are loose or the door is no longer square in the frame. A solid-core door is heavy and exerts considerable pressure on the hinges and door jamb. If rot has weakened the jamb or the framing behind it, screws and nails can dislodge. To get the latch to work properly, you may have to take the door down and repair the damage.
Adjust the door stop if it is angled with respect to the edge of the door. It may be preventing the door from closing all the way. Pry it off with a pry bar, then close the door and allow the latch to engage. Nail the stop back to the jamb in the correct position.
Look for signs that the door has shifted in the frame. These can include angular gaps between the door and the jamb, difficulty opening or closing it, or a tendency for the door to swing open or closed when left ajar. You may also notice that the door is hanging loosely on the hinges. Any of these signs signify the need for door repair.
Pull out the hinge pins and take down the door to readjust the hinges or the jamb.
Unscrew loose hinges from the door or jamb with a screwdriver. Repair any cracked wood behind them with epoxy putty. If any of the screws were loose, fill the screw holes with epoxy putty. Let the putty dry, then reattach the hinges and rehang the door.
Measure the door opening if you suspect the jamb has been pulled away from the framing and is no longer square. Stretch a string from one of the top corners to the diagonal bottom, measure its length with a tape measure, then stretch it between the other two corners. Repair the hinge-side jamb if there is more than a 3/4-inch difference between these two measurements.
Pry off the jamb casing with a pry bar, then pry out the hinge-side jamb, starting at the bottom and working toward the top. Remove all the shims from behind it. Look for signs of rot in the framing and repair it, either by filling it with epoxy putty or, if it is severe, by replacing the framing.
Reinstall the jamb with new cedar shims, placing the shims in pairs behind it at 12- to 18-inch intervals and tapping them together from either side. Use a 4-foot level to plumb the jamb while you do this. Nail the jamb to the framing with 12d finish nails, driving the nails in pairs through each set of shims.
Measure the door opening again to make sure it's square, then rehang the door. If the repair was successful, the door should remain stationary when left ajar.
Check the operation of the latch. If it doesn't work, it may have been thrown out of alignment by the door repair. You can usually repair this by adjusting the position of the strike on the jamb.
Observe the operation of the latch when you close the door to determine whether the strike needs to be moved up, down or laterally. Unscrew the strike and widen the hole behind it in the proper direction with a chisel and hammer.
Fill the old screw holes with epoxy putty, let the putty dry, then screw the strike back on the jamb in the correct position. Close the door and verify that the latch is working.
If neither the door nor the stop appear out of alignment, you can usually restore the operation of the latch by adjusting the position of the strike.
Addressing the cause of severe rot to the framing behind the jamb is as important as fixing the door. A leak in the wall or ceiling may cause even more severe damage if you leave it as is.
Deziel, Chris. "How to Adjust a Door That Will Not Latch." Home Guides | SF Gate, http://homeguides.sfgate.com/adjust-door-not-latch-26951.html. Accessed 22 April 2019.