The one incident in the Chumash concerning masturbation does not have the individual masturbating out of lust. Rather, assuming the improper activity was an act of masturbation, it was done as a rebellion against an obligation to impregnate one's dead brother's wife knowing that the child conceived would be raised not as one's own, but in the name of the dead brother (Genesis 38). Onen (from which the term onanism is derived) spilled his seed on the ground” rather than have relations with his dead brother's wife.
One can learn nothing about the impropriety of sexual lust from this event. As a matter of fact our rabbis tell us that if it weren't for the Yetzer Harah, which in their minds was somewhat equated with sexual desire, a man would never marry and build a famly. We see that according to our Talmudic rabbis , lust used in its proper context serves a positive purpose. They were, however, opposed to actively arousing one's lust when one is unable to direct it to marital cohabitation.
Therefore, the prohibition of masturbation is not connected to lust or sexual pleasure, but rather to the wasting of semen. Whereas the rabbis saw the prohibition against male masturbation as a G-d given directive, they established the prohibition of female masturbation as a rabbinic prohibition against immodest and unseemly behavior.