Castle Palamecia is a long and dangerous dungeon. With a strange exception for most of the seventh floor, you can't Teleport out, and you wouldn't want to anyway. If you should do so, your party will appear outside the castle, but the Airship will appear back in the vicinity of Fynn, and it's a long walk back.
Because you can't leave, and this is a very long dungeon with a lot of treasure off the beaten path, you will fight a lot of encounters here. A few can easily kill you if you're not lucky. Don't be surprised if, despite your best efforts, you cannot clear this dungeon the first time through. If Final Fantasy II has a singular flaw, it's the preponderance of encounters that are simply unwinnable. Short of grinding for hours to raise your characters' magic defense levels, certain attacks are very deadly and subject only to the whims of luck.