1- He created it to show us that life is a trial and we should be careful
2- Prophets and Imams don’t commit sins. What Adam did was not a sin, but he was rather deceives by Satan because Satan took an oath in God’s name that he was saying the truth, and Adam didn’t think he would lie while swearing in God’s name. Now all this happened to show us the consequences of listening to the devil so we become extra cautious and resist his evil whispers.