What was the purpose of the Tree of the knowledge of good and evil

One thing I’ll note is that the tree was there before Adam or Eve. Genesis 2:15 says that God put Adam in the Garden of Eden to till it and take care of it. I assume that includes the tree.

Now, He also said that nobody was supposed to even touch the fruit (Genesis 3:3) so presumably even going near it would be dangerous.

As to why the tree is there at all, I wonder if it was for God. Kind of like someone having a liquor cabinet and telling the kids to stay out of it.