How do the words "ממה נפשך" mean what they mean, i.e. "either way"?
My understanding has always been:
"ממה נפשך" literally means "From what your soul/self," which is short for "[You may interpret this] from what[ever approach] your self [prefers]."
The closest entry in The Practical Talmud Dictionary is for "מה נפשך," which R' Frank translates as "What is your desire [to say]?!" or "Which position would you adopt?!" - a rhetorical question that implies that whichever of the two positions about to be offered you choose, you'll end up losing.
It could be that "ממה נפשך" is just a variant form of the same expression, or that the extra 'מ' indicates that your position is about to be attacked "from" (or by) a "מה נפשך" argument.
The Dictionary cross-references its entry on "נפש," one of the senses of which is desire/wish. R' Frank gives the same example of this meaning in Biblical Hebrew that Shalom does.
This term is used when there is a kushya i.e. difficulty on the both צדדים i.e possible sides. This definition is by Darchei Hatalmud (or Hagemara) by Rabbi Yitzchak Kanpanton. The "instruction" of this term is for you to understand clearly what are the difficulties on both sides. See if it is a chiddush( i.e.new idea) to be able to ask the kushya. Do you have to accept certain premises in order to be able to ask the kushya?