The place or device on a ship designated for performing excretory functions, something a lubber might crassly call the "toilet".

Human beings have been messing about in boats for millenia, and until very recently the answer to a call of nature at sea was to lean over the side, pull down one's pants, and let loose. There are several hazards in this action, most of which we won't go into here, but chief among them is the danger that a rogue wave might come along and then it's man overboard. The loss of a crewmember makes it harder to get work done, something that irritates the officers.

The answer to this on a larger ship was to extend a board with several rear-end-sized holes out over the water. This board was usually located at the front ("head") of the ship. Although the aforementioned waves would serve as a natural flushing mechanism (in addition to an occasional nasty icy surprise), the real reason for the board's location was to prevent the offending material from falling through portholes at the rear of the ship into the officers' cabins.

The natural names a Jack might use for this device among his shipmates would probably have been frowned upon in mixed company, and so, visiting the "head" became his primary euphemism.

Today, "head" refers to any marine toilet, or the small cabin that encloses the plumbing fixtures. Be sure to close the petcocks before running her hard, or you might wind up on the bottom!

A little help in confirming bits of this from is obliviously hilarious.