The joke is a pun. A fathom is a unit of length equal to six feet (approximately 1.8 m), chiefly used in reference to the depth of water. One could also use the word 'fathom' to mean 'understand', so the pirate could not understand why they ran aground, but there may not have been enough fathoms for the ship to sail through.
When the pirate captain ' s ship ran aground he couldn ' t fathom why .