Question: "Why did God put that tree in the garden?"
Short answer: I don't know.
Longer answer: I'm not sure anybody knows definitively, but here are some things to think about.
1. The command to not eat of the Tree of the Knowledge of Good and Evil (TKGE) is an opportunity for the the creature to express love and trust in his Creator. The negative commnad ("do not taste") serves as a test of obedience to the loving command given by God. It gives the creature a postive way to express his turst and love. The issue of trust is brought out in fuller relief when we evaluate the tatic of the tempter. "Has God said ..." (3:1) and "Surely, you will not die" (3:4), are clear attacks on the trustworiness of the Creator's words to Adam.
2. Alongside the issue of trust is the issue of authority. The Creator has implicit authority over the creature and so the divine prohibition is opportunity to recognize the authority of God.
3. God has from the beginning of creation, always been interested in the development of faith in the creature for Himself, the Creator. Faith in God is demonstrated when the creature obeys the commands of God before understanding.
[Smith, M. H. (1994; Published in electronic form by Christian Classics Foundation, 1996). Systematic Theology, Volume One : Prolegomena, Theology, Anthropology, Christology. Index created by Christian Classics Foundation. (electronic ed.). Greenville SC: Greenville Presbyterian Theological Seminary Press.]
A. A. Hodge speaks very pointedly as to why the command not to eat of the tree of knowledge of good and evil was selected as the test of covenant obedience. Perfect conformity of heart, and perfect obedience in act to the whole will of God as far as revealed.––Deut. 27:26; Gal. 3:10; James 2:10. The Command to abstain from eating the forbidden fruit was only made a special and decisive test of that general obedience. As the latter forbidden was morally indifferent in itself, the command was admirably adapted to be a clear and naked test of submission to God’s absolute will as such. The forbidden tree was doubtless called the tree of the knowledge of good and evil, because through the disobedient eating of it mankind came to the thorough experience of the value of goodness and the infinite evil of sin.
I have heard some who wish to take pot-shots at the Bible say that it was unfair of GOd to test Adam and Eve in this way. Further, they say that the text doesn't make sense because Eve and Adam could not have known that eating of the tree would produce evil results because they didn't know good from evil. In other words, that a real choice, implies a real knowledge of the difference between good and evil already.
But the reality is that obedience does not require experiential knowledge of good and evil. It requires recognition of an authority above yourself and trust. It is not the eating of the fruit that is sinful but the rebellion against God's authority and the distrust of his spoken word. The clay does not tell the potter what to do. Or as I told my four year old nephew, "It is generally not a good idea to give God advice on how to run the universe."[more to come, ... Maybe!]