Leviticus 18-20 deals with sexual activity. Canaan had become a stronghold for the demonic powers linked with sexual immorality. The penalties for sexual immorality are harsh, but they were designed to prevent the Israelites from being polluted and defiled. Chalal, the Hebrew word for pollute, is used five times in these chapters. The following verses expand this theme.
The Israelites and their families were very vulnerable to the spirit of lust that had been rampant in the land. Their only protection for their family life was to stamp out all sexual immorality.
Do not defile yourselves in any of these ways, because this is how the nations that I am going to drive out before you became defiled. Even the land was defiled; so I punished it for its sin, and the land vomited out its inhabitants (Lev 18:24-25).
You must not do any of these detestable things, for all these things were done by the people who lived in the land before you, and the land became defiled. And if you defile the land, it will vomit you out as it vomited out the nations that were before you (Lev 18:26-28).
Everyone who does any of these detestable things—such persons must be cut off from their people (Lev 18:29).
Do not follow any of the detestable customs that were practiced before you came and do not defile yourselves with them (Lev 18:30).
The situation is totally different now that Christ has come. People can now delivered from sexual evil the name of Jesus by the power of the Holy Spirit. We no longer need to stamp out all sexual immorality, because we have much better protection through the cross of Jesus. He was able to eat and drink with prostitutes and sinners without fear. We can do the same because we have the protection of the blood of Jesus. We no longer need to separate ourselves physically in like the Israelites.
The power of the cross did not exist in Old Testament times, so separation and destruction of evil was their only protection. Rather than condemning Israel for being harsh, we should be grateful that we have better protection.