If you're religious, the prohibition is based on Genesis 38, in which a fellow called Onan avoided his familial obligations towards a woman, having sex for pleasure but pulling out to avoid conception. This irritates God, who promptly strikes him dead. http://en.wikipedia.org/wiki/Onan has an in-depth explanation from multiple doctrinal perspectives.