Abraham's wife Sarah gave her female slave Hagar to Abraham to have sex with in order to beget an heir (Genesis 16:1-4). Both of Jacob's wives, Rachel and Leah, gave their respective female slaves to Jacob to have sex with in order to beget heirs (Genesis 30:1-13). Judah once picked up a woman he presumed to be a prostitute, and then begat two of his sons through this fornication (Genesis 38:11-30). Samson once had sex with a prostitute, and then immediately afterwards defeated his enemies through the power of God (Judges 16:1-3). The Bible doesn't seem to have a big problem with premarital sex as a general rule.
Nor does the Bible, as a rule, require people to remain a virgin until marriage. Young women at the time were generally expected to be virgins before marriage, but this appears to only be customary within the context of a culture which practiced arranged marriages. In this system, virgin brides were highly prized by potential grooms and fetched a premium bride-price for the woman's family. The biblical inclination towards virgin brides appears to have only social and economic significance, yet it would seem that Christians have reappropriated the concept for a different purpose. Instead of having social and monetary value, remaining chaste until marriage has been given religious and spiritual value. Christians believe that God is pleased with those who keep their virginity and save sex for marriage, and that to do otherwise is a sin. Also, even though it was really only the women who were expected to remain chaste for their husbands, and not the other way around, Christians now expect men to also remain virgins until marriage.
My question is: when did this happen? At what point in church history did they adopt the ideas that premarital sex was a sin and that remaining celibate until marriage was a virtue? And why did the Church do this?
While not explicity answering your question, When did controlling cultural sexuality become such a major issue for Christians? by /u/BBlasdel from the FAQ may help until a more specific answer can be provided
There are a few areas that should be clarified before answering this question.
First, you note a number of scriptural references where biblical figures are depicted having premarital sex. The assumption is that these depictions tacitly approve of the behavior of the individuals. However, that's not necessarily the case - while many modern media approaches do take that approach, imputing those motivations to Biblical authors may lead us into troublesome spots. For a modern example of an approach to media where acts considered immoral by the creators/audience/approvers must be met with in-story consequences or condemnation, see the Comics Code.
So let's look at the stories you mention:
A question that might best answer your question is "what does the Bible mean by "sexual immorality?" There's not one blanket answer, because some parts of the Bible are more specific than others. For instance, Leviticus contains clear prohibitions against adultery, incest, homosexuality, bestiality, etc. Other texts, like Genesis 2, seem to imply an understanding of sex and marriage as inherently connected (a man and his wife are joined by becoming "one flesh"). But in the New Testament, we start getting much broader. Many passages (such as 1 Corinthians 818, 7:2, John 8:41, etc.) refer broadly to "sexual immorality" - typically, the Greek word "porneia." So what would the readers of the New Testament have understood porneia to mean? Would it have just included the specific and explicit commandments in the Torah? Probably not. The word porneia was translated into Latin in the 300s as "fornicati" and other related words, from whence we get fornication - any (typically consensual) sex outside of marriage. We know that the Roman audience of the New Testament authors would have understood porneia/fornication to refer to acts including prostitution, but also just plain sex outside of marriage. We can see that reflected in the story of Mary and Joseph, where Mary's pregnancy is met with shame, as she and Joseph aren't married yet.
Tl;dr: