Ancient ships had a castle, as may be seen in the tapestry of the House of Lords, representing the Spanish Armada. The term forecastle means before the castle. The Romans called the castled ships naves turri'tæ'.
“That part of the upper deck forward of the foremast ... In merchant
ships, the forward part of the vessel, under the deck, where the
sailors live.” —
Source: Dictionary of Phrase and Fable, E. Cobham Brewer, 1894
More on Forecastle from Infoplease: