9 times out of 10 this happens when the catch gets sticky. Try giving it a good squirt with wd40 in all the nooks and crannies round the catch, and a good soaking through the key hole too, then work it a few times to get it moving freely. If this doesn't work then it'll probably need a new door lock mechanism, but should be looked at by a mechanic first just to confirm!