The commander of the flight had left the cockpit for a short while to visit the toilet and on returning to the cockpit found the door locked.
The door had got jammed and all efforts to open it, even from the inside by the co-pilot, failed.
The Air India flight was forced to land by the co-pilot after permission from ground control. The door was then fixed by ground maintenance engineers and the plane continued its journey less than three hours later.
The planes have been grounded worldwide since the beginning of the year over a string of incidents, including fuel leaks, a cracked cockpit window, brake problems and an electrical fire.