We do not know exactly how the hijackers gained access to the cockpit; FAA rules required that the doors remain closed and locked during flight.
The hijackers had discovered some way to gain access to the cockpit.