There is no grammatical reason for it; it is simply traditional for certain classes of nouns, including
to be treated as female, especially in literary usage.
Some tie this to personification: Western national personifications are overwhelmingly female, for example, as is Mother Nature herself. I think that is reductive, however. England is traditionally personified as John Bull, a male, yet the usage was England and her allies. The USS Andrew Jackson was invariably a she, even if her namesake was a robust adherent of traditional masculine norms. Furthermore, a ship or airplane or city may be called she, but the relative pronoun for them will remain which, not who. Anglophones are not imagining Marianne when speaking of France in her multiplicities.
The most common explanation is that institutions and inanimate objects came to be referred to as she when perceived as nurturing or protective, like a mother; they acquired a social gender even if they do not have, and could not have, a biologically-based one. It is not related to grammatical gender, leastways what grammatical gender the Latin navis has. English does not have a grammatical gender system any more, and back when it did, schip was grammatically neuter.
The use of feminine pronouns with those nouns is increasingly limited, because some see it as patronizing and otherwise outdated. Given current sensitivities, I'm certain an essay like "Why We Call a Ship a She" would never have been published in a respectable magazine, and coming from a well-respected historian and retired admiral, it would have provoked no small controversy if it had. Even the Scottish Maritime Museum has, to some controversy, replaced she and her with it.