Did God invent sex?

Yes. This was part of God’s intention in deliberately made men and women different. In Genesis 2:24 we read, That is why a man leaves his father and mother and is united to his wife, and they become one flesh. That is to say, God intended that a man and a woman would be united in a permanent, public, exclusive, life-long union of marriage, and that this union would include the physical union of sex.