Recently I used the slang term "paja mental" with someone who was not familiar with it, and I had to explain that, among other meanings, the slang expression refers to a sort of "wishful thinking" where the idea is so fantastic, impossible, erratic, nonsense, etc. that it's like an exercise of "mental onanism". Quoting this site (AsíHablamos.com) it would be an "erratic, complicated, absurd and too complex reasoning only to be understood by the one doing it".
I also had to explain that "paja" and the expression "hacerse una/la paja" are slang for masturbation. They asked me for the origin of this expression and I could not respond. I did a quick search online and could only find one entry in Meneame which didn't seem very trustworthy (also, I'm at work and I need to avoid NSFW sites, which unfortunately might be among the results of your query, given the keywords involved).
How did the term "paja" and the expression "hacerse una/la paja" come to refer to masturbation?