In my opinion this passage suggests the author is making a double entendre, not only a joke.
First, it is clear that a headwind will go against direction which the ship wants to travel and a wind from astern will push in the direction of travel. By bringing that into metaphor with the phrase "For as in this world", Herman Melville is, foremost, suggesting that hardships are more common than advantages. As for the Pythagorean maxim, there were many maxims spoken in the Pythagorean school, so that singling out just one might not give the full meaning of what Melville was saying. This idea is also supported by the long collection of quotes about whales which Melville places at the beginning of the book.
I believe the most relevant maxim, given the context of the passage, would be koinà tà phílōn "All things in common among friends" from the communal life of the Pythagoreans.
The adherents were bound by a vow to Pythagoras and each other, for
the purpose of pursuing the religious and ascetic observances, and of
studying his religious and philosophical theories. The members of
the sect shared all their possessions in common and were devoted
to each other to the exclusion of outsiders. Ancient sources
record that the Pythagoreans ate meals in common after the manner of
the Spartans. One Pythagorean maxim was "koinà tà phílōn"
("All things in common among friends"). - Wikipedia
In other words, Melville is saying in one sense of the double entendre, that hardships are more common among the community (sailors), as long as you stay with the community. This idea is supported in the author's description of a sailor as a slave and in the following sentence:
For as in this world, head winds are far more prevalent than winds
from astern (that is, if you never violate the Pythagorean maxim), so
for the most part the Commodore on the quarter-deck gets his
atmosphere at second hand from the sailors on the forecastle. He
thinks he breathes it first; but not so. In much the same way do the
commonalty lead their leaders in many other things, at the same time
that the leaders little suspect it
The more risque meaning of a "fart joke" comes from the Pythagorean rule of not eating beans which would produce flatulence. This theory is supported by Melville's description of the location of the forecastle:
No, when I go to sea, I go as a simple sailor, right before the
mast, plumb down into the forecastle, aloft there to the royal
"plumb down into" would suggest a vertical drop which is in reality horizontal from mast to forecastle, which later helps imply a "drop" from the body's head to butt. A fart oriented as described would manifest in the same direction as an "astern" wind.
To recap, the fart joke adds to the idea that the leader does not always know what is leading him. However, without the bonds holding sailors together, there is no lead by community. The sense of lead is awkward in Melville's sense that one leads into hardship often, metaphorically represented by his commodore getting lead by the sailors and the sailors getting led by fate.