When God tells you not to do something, it's not because of Him. It's because of you. He knows what sin will do to you. He knows it will paralyse your faith and make it ineffective. He knows that sin will bring in fear and uncertainty. So He tells you to keep sin away for your sake. Not because He has a problem with you sinning. He only has a problem with the impact of sin on your faith walk, for without faith, it is impossible to please God.