In “the olden days”, ships did not have bathrooms. As unclean as it may sound, their system worked for them at that time. Beyond the bow of the boat there was a bowsprit that was simply covered with a rope webbing or wooden grating as shown, and was open to the sea below. Sailors needing to relieve themselves would do so over the webbing and any waste fell through to the sea, keeping the area clean. This was a simple and effective system for the times.
In nautical terms, head refers to the top or forward portion of a vessel. The head of the mast or the head of the bowsprit or the term dead ahead are examples. Back then, when a sailor needed to relieve himself, he would have to go forward saying, “I need to go to the head of the ship”. That terminology has stuck with us and to this day boaters still refer to the bathroom as the “head”. The word head confusingly refers to both the room and the toilet.