Ten has the keys to the old part of the ship, the part that they now use as a prison. He's had them for days, hidden under his belt, and no one has thought to search him. He has the keys, and he has the codes, and he definitely has the motive.
(Ten visits Kun in the prison wing of the ship.)