After a quick google, it appears nobody knows for sure. It could be because 'in the Romance languages, the word for "ship" is always in the feminine. For this reason, Mediterranean sailors always referred to their ship as "she", and the practice was adopted over the centuries by their English-speaking counterparts'
Or
'a ship "was nearer and dearer to the sailor than anyone except his mother." What better reason to call his ship "she"?'
However, not all cars a 'she'. My car is Dave :)