That was a severe penalty for early withdrawal.
More seriously there is a question of whether the penalty was for the act in general or because the act was in defiance of the command for Onan to "keep his brother's name alive" with his brother's widow.
Also, that has nothing to do with female masturbation, as it refers to "spilling of seed."
Of course, if that passage says anything about masturbation, it directly contradicts the author's assertion.