17but of the tree of the knowledge of good and evil you shall not eat, for in the day that you eat of it you shall surely die.”
The Holy Bible: English Standard Version. (2016). (Gen 2:17). Wheaton, IL: Crossway Bibles.
All of chapter 2 speaks of what God did to make his children happy, and this special tree was no exception.
God never designed humans to be puppets or robots whom he regulates by pulling strings or pressing buttons. By placing the tree of the knowledge of good and evil in the garden, God was giving Adam the opportunity to obey God of his own free will. In so doing, God realized the risk involved, that Adam might choose to disobey him. When Adam came from the hand of his Creator, he was in a state of created innocence. By giving Adam the command not to eat, God was offering him the opportunity to progress from created innocence to conscious holiness. God wanted his highest creature to be holy by choice, not just by accident.
Martin Luther used an illustration that makes God’s intent clear.That tree in the middle of the garden was Adam’s place to worship God. There he was reminded of God’s goodness to him; there he could thank God for his mercy; there he could respond by giving God glad obedience.
The Creator had endowed Adam with a free will, an inborn freedom to do what pleased God. God wanted him now to exercise that free will. If Adam had, the experience would have produced a knowledge of good and evil similar to that which God himself has. Adam’s intellect would have become more keenly aware of what God wanted and what he didn’t want. His emotions would have found joy in the Creator’s will and would have convinced him of what a dreadful thing it would be to rebel against God. And Adam’s will would have consciously chosen to follow God’s command to have nothing to do with the forbidden fruit.1
1 Jeske, J. C. (2001). Genesis (2nd ed., pp. 38–39). Milwaukee, WI: Northwestern Pub. House.