After Alfred locked himself in the room, Lucy turned off the power for that area from the surveillance room. Alfred was surprised/scared when the power went out and accidentally dropped the masterkey, which fell and slid under the door. Lucy picked up the key, unlocked the door, killed Alfred, left the room, and locked the door again.