At first glance, it may seem that God is unspeakably mean in His instruction concerning sin. Yet, when we realize that the Bible also warns that “the wages of sin is death”, we realize why God wants us to stay away from sin. Among other things, it’s for our own good.
A good parent understands this. If a parent of a young child saw them playing in a road with a lot of traffic, their love for their child would demand that they threaten serious consequences if they played in the road again. Failing to provide serious consequences for a child who could potentially die from their poor choices would call into question the parent’s love for their child.
Since God loves us, he threatens serious consequences when we sin. Any good parent would.