Can't understand how you can lock it if it doesn't stay shut on the latch. You can't be fully locking the door. Any way it sound like the door has warped bring the latch bar away from the latch/lock plate on the jamb. try removing the door stop, top and both sides close the door to see if it latches, if so re fix the door stops in the new position don't fix tight against the door or you'll be back where you started an un lockable door. If it doesn't latch check the position of the lock to the plate then alter the position of the latch/lock plate. then try again if it works re-fit the door stop.
Bob, August 2005