The strike plate, or metal piece on the jam where the door latches, might be placed too low or too high. This should always be the first thing you check when identifying a door that's not closing correctly. Look for marks on the strike plate that show the latch going above or below the hole. If you see these marks, use a metal file to file down the hole of the strike plate to make it lower or higher so that the latch can go in. If that wasn't your problem, then the problem is probably with your hinges. They are probably uneven, with one being too far in or out from the jam. Close the door as much as possible and look for uneven lines. The gaps all around the door should be the same all the way across (along the hinge line, at the top of the door, bottom of the door, and on the side of the door with the latch). The easiest option is the just adjust the center hinge, but you'll probably want to adjust either the top or the bottom hinge depending on the situation, since this should have the most impact. No matter which hinge you need to fix, the process is the same. Unscrew that hinge so that you can access the jam behind it. Cut a piece of milk carton or thin cardboard to the shape of the hinge recess and place it there. Return the hinge flap and screw it into place. Usually, if there's a gap on the top latch side, you'll need to adjust the bottom hinge. If the door is bumping up against the top latch side of the jam, you'll need to adjust the top hinge.

Summary:
Check your strike plate. Check the hinges. Adjust the hinge.