Prop the door open, and locate the metal strike plate screwed to the door frame. A strike plate is the metal plate in the door frame with a hole for the latch when the door is closed. Remove the screws in the strike plate, and pry the plate out of the wood.
Find a metal tab extending backward inside the latch hole on the strike plate. Using a pair of pliers or a slotted screwdriver, carefully bend the tab inward so it begins to take up some of the space in the latch hole. Don't bend the tab too much or apply too much force. Moving the tab a few millimeters is usually enough.
Screw the strike plate back into the door frame, and close the door. Push the door while it is latched; it should no longer rattle back and forth.
Adjust the door frame and strike plate more if the door continues to rattle. You will have to chisel away some of the door frame and set the strike plate further back.
Close the door, and measure the distance the door travels, when pushed, away from the doorstop, which is the piece of wood that stops the door from passing through the frame.
Shift the strike plate the same distance in the opposite direction, and screw it back into place. You might have to chisel a wider latch hole in the door frame to make sure that the lock bolt still fits.