That wasn't a law, but a commandment, and one originally ordained and intended by God to protect life, not to bring death. Satan deceived Adam and Eve, twisting God's intended purpose for his own, which, through Satan, resulted in death for all. The law is holy, but it is through sin that we attempt to justify ourselves by the law that death, not life, emerges.
[Rom 7:8-10 KJV]
8 But sin, taking occasion by the commandment, wrought in me all manner of concupiscence. For without the law sin [was] dead.
9 For I was alive without the law once: but when the commandment came, sin revived, and I died.
10 And the commandment, which [was ordained] to life, I found [to be] unto death.
[Rom 7:5 KJV]
5 For when we were in the flesh, the motions of sins, which were by the law, did work in our members to bring forth fruit unto death.
[Rom 7:8-10 KJV]
8 But sin, taking occasion by the commandment, wrought in me all manner of concupiscence. For without the law sin [was] dead.
9 For I was alive without the law once: but when the commandment came, sin revived, and I died.
10 And the commandment, which [was ordained] to life, I found [to be] unto death.
[Rom 7:5 KJV]
5 For when we were in the flesh, the motions of sins, which were by the law, did work in our members to bring forth fruit unto death.
God is Sovereign and Omniscient. He planted one tree he forbid be touched or eaten of. While the serpent knew Gods law was not to eat of it.
That's how of all trees he ascended into that one so to tempt innocent minds who knew not good or evil. And therefore did not know what they were doing or were suppose to do in obedience.
They were destined to fall. Which is why the lamb was slain before the world was made and the lambs book of life was written before then too.
By one man sin entered this world.
Sin predated the world in order to enter into it. And we know how. Because Lucifer sinned in Heaven leading angels to war against God.