Actually, I'm pretty sure it's considered a sin. 10 years of Catholic schooling, and I remembered the quote and was able to find it thanks to google:
"Then Judah said to Onan, 'Unite with your brother's widow in fulfillment of your duty as brother-in-law, and thus preserve your broher's line.' Onan, however, knew that the descendants would not be counted as his; so whenever he had relations with his brother's widow, he wasted his seed on the ground, to avoid contributing offspring for his brother. What he did greatly offended the lord." Genesis 38: 8-10
People back then thought of semen as a seed. To them, it was a very small baby waiting to be "planted" in the womb where it would grow. To waste the sperm was to kill a baby. Therefore, pulling out, as is the case in the quote, or masturbating would be considered a sin.
I so enjoy being an atheist that can quote scripture.