Why is sex a sin?
The short answer to your question is that sex is not a sin, but it can become a sin in certain situations.
"Marriage is honorable among all, and the bed undefiled; but fornicators and adulterers God will judge" (Hebrews 13:4). The Greek word koite is translated as "the bed" in this passage. It can refer to the place where a person sleeps, such as in Luke 11:17, but it also refers to what takes place in bed between a husband and wife. In other words, this is the Greek word for sexual intercourse.
What the writer of Hebrews is stating is that in all cultures, the state of being married is held as an honorable state; therefore, when sex takes place in marriage it is not something dirty, unclean, or sinful. However, when sex takes place outside the bounds of marriage, it then becomes a sin -- either fornication (a general word for sex between two unmarried partners) or adultery (a more specific word for sex between two people where at least one is married to someone else).
If you stop for a moment and think about it, you will realize that there are many things that are righteous in some circumstances and wrong in others. There is nothing wrong with eating, but overeating is the sin of gluttony. You can drink, but drinking alcohol will lead to the sin of drunkenness. Medicines promote healing, but abusing drugs will kill you. What God has stated is that sex right within marriage, but wrong outside of marriage. In fact, we can go further and state that sex is a duty within marriage. "Now concerning the things of which you wrote to me: It is good for a man not to touch a woman. Nevertheless, because of sexual immorality, let each man have his own wife, and let each woman have her own husband. Let the husband render to his wife the affection due her, and likewise also the wife to her husband. The wife does not have authority over her own body, but the husband does. And likewise the husband does not have authority over his own body, but the wife does. Do not deprive one another except with consent for a time, that you may give yourselves to fasting and prayer; and come together again so that Satan does not tempt you because of your lack of self-control" (I Corinthians 7:1-5). "The affection due" is a reference to the duty of sexual intimacy owed to one's spouse.
The fact that God declared sex outside of marriage a sin ought to be enough to convince anyone not to engage in such action, but the Bible does go further to explain why God placed such a restriction on sexual intercourse.
One problem that people often ignore is that sex creates a bond between sexual partners. "Therefore a man shall leave his father and mother and be joined to his wife, and they shall become one flesh" (Genesis 2:24). By calling the couple one flesh, God is expressing more than the physical joining during intercourse, though that act of oneness is obviously included. But the act of sex also creates emotional and spiritual ties between the partners. It is those ties that led Paul to argue that prostitution is wrong. "Do you not know that your bodies are members of Christ? Shall I then take the members of Christ and make them members of a harlot? Certainly not! Or do you not know that he who is joined to a harlot is one body with her? For "the two," He says, "shall become one flesh." But he who is joined to the Lord is one spirit with Him" (I Corinthians 6:15-17). When a person engages in sex, he creates a spiritual bond with that person. But what will be the outcome of that bond? Obviously, a prostitute is not interested in spiritual matters. She will lead a person away from righteousness. "Do not be deceived: "Bad company corrupts good morals"" (I Corinthians 15:33). Or as the writer of Proverbs warned, "Now therefore, my sons, listen to me, and pay attention to the words of my mouth. Do not let your heart turn aside to her ways, do not stray into her paths. For many are the victims she has cast down, and numerous are all her slain. Her house is the way to Sheol, descending to the chambers of death" (Proverbs 7:24-27).
There is also a secondary problem created by bonding with someone through sex outside of marriage. It is rare for such relationships to last. Typically, unmarried sexual partners have an average of seven partners, at least according to one study. As a person moves from partner to partner, he makes and breaks the bonds which tie him to that person. The first break-up is devastating, but the next break-up, while heart-wrenching, is not nearly so bad as the first. The third becomes even less bothersome. With each breaking of the spiritual bonds, the person becomes less and less able to retain his bound with his current partner. As a result, when troubles come, the natural impulse is to "solve" the problem by terminating the relationship. This is why people who have sex prior to marriage have a far higher divorce rate than those who are virgins on the day of their marriage. People used to cohabitating outside of marriage have trained themselves to easily sever relationships.
Such a callous view of relationships also impacts a person's life in other areas. They are not able to make and retain commitments easily. Hence, they tend to make unstable Christians. The first sign of hardship often sends them out the door looking for an easier religious experience.
The use of multiple sexual partners also leads to another problem: disease. There are numerous diseases that are spread by close contact or by the exchange of body fluids, both of which happens during sexual intercourse. This is why you find warnings concerning the aftereffects of sex outside of marriage, "and you mourn at last, when your flesh and your body are consumed" (Proverbs 5:11). Or, "Whoever commits adultery with a woman lacks understanding; he who does so destroys his own soul. Wounds and dishonor he will get, and his reproach will not be wiped away" (Proverbs 6:32-33).
Solomon explains why multiple sex partners are unhealthy by comparing sexual desire and intercourse to thirst and having a drink of water. "Drink water from your own cistern, and running water from your own well. Should your fountains be dispersed abroad, streams of water in the streets? Let them be only your own, and not for strangers with you. Let your fountain be blessed, and rejoice with the wife of your youth. As a loving deer and a graceful doe, let her breasts satisfy you at all times; And always be enraptured with her love. For why should you, my son, be enraptured by an immoral woman, and be embraced in the arms of a seductress?" (Proverbs 5:15-20). Thirst is a strong desire within the human body. It is not one that we can easily ignore. Yet, when we are thirsty, our favored place to quench that thirst is from the tap in our own home. Why is that? It is because we trust our own water source to be free from impurities. Back in the ancient days, open gutters were used to carry wastewater out of town. No one in their right mind would quench their thirst by taking a drink from the gutters -- no matter how thirsty they might be. Why is that? Because we know the water is dirty. It is filled with disgusting things. You don't know where that water has been or for what it has been used.
In the same manner, sex is a very strong desire in the human body; a desire that is not easily ignored. Yet, why would a person quench his sexual desire with a loose woman? How many other partners has she had? How many diseases has she picked up? Why would anyone expose themselves to all those diseases just to have sexual intercourse? It ought to be as repulsive to our minds as drinking a glass of sewage.
Finally, we need to realize that the natural consequence of sex is children. Not every act of intercourse produces children, but that is the ultimate normal outcome. When a child is conceived outside of wedlock, what kind of life has this couple condemned this innocent child to live? The ideal place to raise a child is in a home where there is a mom and dad committed to their relationship and to their children. A child being raised by only one parent, or worse, facing a multitude of "moms" or "dads" as partners go in and out of his parents' lives, is faced with many troubles. Some women give their child up for adoption, which is far better for the child, but it leaves both the child and the mother wondering why the relationship was severed. Sadly, the most popular way to deal with an unwanted pregnancy is to terminate the life of the child. An innocent human being is killed simply because two people wanted intercourse. Their "lovemaking" results in the murder of a child.
Sex outside of marriage is a sin because God said so. God said so because it is in the best interest of everyone involved.