Sex prohibitions and marriage all stemmed from -
1. Ancient inheritance rights
2. Women not being able to own property
A "bastard" is an illegitimate male child with no inheritance rights. A female child born out of wedlock or from a legitimate marriage had no inheritance rights.
Although men married a woman, it was for the sole purpose of producing a legitimate male heir. Men still slept around with whomever they wished.
Physical intimacy is important for physical, mental, and emotional health. The "sin" in not unmarried sex. The sin is producing a child outside of a marriage.