25 years after it was released in theaters, who knew Aladdin would be the subject of a new and exciting fan theory?
According the the theory, the Cave of Wonders was actually created by the previous owner of the magic lamp, using the three wishes of the Genie to give him unending wealth, and to ensure that only someone truly worthy would find the lamp once he was done with it. Let's break this down.
The theory states that the previous owner used the first wish to gain an incredible amount of wealth. Since measurements were different back then, he could've said something to the effect of, "Enough treasure to fill a cave." This explains where all of the gold came from, and possibly how the cave came to be.
Wish number two would have been for some kind of transportation that could get him anywhere he needed to go, something that wouldn't ever run out of energy or fuel. This created the magic carpet.
The owner's third wish is where things get tricky. Since he had an unlimited amount of money, and he could go anywhere he wanted, the only thing he wanted was to share the fortune with someone who deserved it. This is how the Cave of Wonders was designed. A "Diamond in the rough" would follow the rules and only go to get the lamp, ignoring the rest of the treasure and staying honest.
This would have ensured that someone like Aladdin ended up in possession of the Genie's powers, rather than someone like Jafar.