The Gemara (Pesachim 54a) tells us that the ability of man to do teshuva was one of the seven things that Hashem instituted before He created the world. The whole purpose of the entire creation was to create man to serve Him. Man's service only has meaning if man has bechira chofshis, so man had to be created with the ability to choose to sin.
This is assumed to be the meaning of the passuk that says man that was created "b'tzelem Elokim" - he was created with total freedom of choice. Just as there is nothing forcing G-d to choose one thing or another, so too man is completely free his decision making.
The Torah (Breishis 2:7) tells us that Hashem took sand from "ha'adama - the earth" to form man. Rashi in his commentary quotes the understanding of the medrash that the word "adama" is an allusion to the earth of the altar in the Beis Hamikdash. Man has built into his being the ability to do teshuva. Freedom to choose which path to proceed on is essential to the make-up of man. Even after having made his initial choice, man has the ability to totally undo a decision, in either direction (for the good or for the bad), and choose a totally different route.
In the weekday shmoneh esreh the first request we make in the middle section (containing all of our bakashos) is for intelligence and wisdom, i.e. that we should be able to function as normal human beings. What distinguishes the humans from the animals is our sechel. The very next request in the shmoneh esreh is that we should be able to exercise our ability to do teshuva. This too is integral to the human condition. All people are prone to sin, but Hashem built into all of us the ability to do teshuva.
The medrash (Breishis Rabba 3-9) says that Hashem originally created other worlds and destroyed them, until he finally created this world that we are familiar with. Certainly if Hashem had willed a beautiful and wonderful world in the first place, that would have come about, so why did He initially will several imperfect worlds into existence just to destroy them and then start all over again? Apparently Hashem wanted to teach man the lesson of "starting all over" (see Nefesh Harav page 68.)
Some have the attitude that by sinning and going against the wishes of Hashem they are exercising their bechira chofshis to the greatest degree! From a perverted perspective this is certainly correct. But also included in the concept of tzelem Elokim is using this power of bechira for a creative, positive, and productive purpose. Hashem chose freely to create an entire universe, so we should emulate His ways by using our bechira chofshis for positive purposes - "u'bacharta ba'chaim" (Devarim 30:19) - to choose to go b'derech Hashem. Even after having already made an improper choice, we must use our bechira chofshis to scrap "our world" and "start all over again", just as He did.