The Djinn is really Emperor Palpatine.That hissing, croaking voice, the cowled, disfigured face and hunched-over appearance, the way he encourages people to give in to their heart's desire so he can then twist it and use it against them... it can only be Palpatine! And for bonus points, when he assumes a more human form, it's in the form of a handsome, sophisticated Smug Snake in a business suit who charms and manipulates people, just like Palpatine in his chancellor days. But how, how could it have happened? Well, Star Wars takes place a "long long time ago", and we know from the Expanded Universe that Sith Lords can exist as Dark-Side spirits after they've died. The Djinn is actually Palpatine's spirit, and the Djinn world is what the Dark Side of the Force looks like from the perspective of a fallen Sith. And Palpatine's feeding on people's weaknesses, bringing their wishes to life (maybe through a mind trick, by making people think that he's tormenting them so they'll die from the mental shock) and gradually making the Dark Side strong enough that he and the rest of the dead Sith Lords can manifest on Earth and claim it as their own. And Zoroaster must have been using Jedi techniques passed down over the centuries, originally gleaned from a Republic ship that crashed to Earth in ancient times. After all, where else could he have gotten that Sith holocron he used to trap Palpatine's spirit, which modern people mistakenly assumed was an opal?
The Djinn in the first two films is Iblis.Now mind you this is really more of a shot in the dark, but in my limited knowledge of the Muslim religion, but I'm pretty sure Iblis was a Djinn and in the first two films, the Djinn seemed to have a sort hierarchy to the other Djinn and was the most evil out of them and seemed to be the ruler of the Hell like dimension the Djinn dwell in.
- Well, leaving aside the fact that the Djinn in the Islamic religion are just another race of beings as capable of good and evil as humanity, Iblis/Shaytaan himself is neither impulsively evil nor powerful (he is prideful and disobedient and a hinderer of humanity, but he ultimately still worships God in his own way). His status in Islam is the exact same as it is in Judaism; God just created him to be an obstacle for humanity on the path to true faith through nudging humans towards evil inclinations but cannot actively influence or force outcomes except through subtle temptations, contrary to the Devil of Christianity who seems to be some kind of dark god. Iblis serves Allah's design like all other aspects of creation. Also, he does not rule Hell (which in truth is an idea drawn from Paradise Lost rather than actual Abrahamic theology). That role is assigned to an angel named Malek in Islam, who in turn governs Hell on the orders of the Almighty.
The Djinn is only compelled to grant wishes from the one who woke him.He grants wishes to others in order to wreak havoc and acquire power from their souls. However, he dosen't have to, or at least he can give such people an opportunity to wish again, or "rephrase" their wishes. For example in the second film, the man in the jail cell just wanted the Djinn's shoes. The Djinn didn't immediately comply because he thought it was a stupid wish, and was able to get the man to instead wish to "go through the bars." The security guard asked the Djinn to leave, and the Djinn "seemed" to be compelled, but the security guard then changed his wish.
- Or he's allowed to grant potential wishers an opportunity to rephrase what they want. If the guy insisted, saying "No. I want your shoes. Now!" the Djiin would have to comply. Same as the first film with the security guard wanting the Djinn to leave, but changed his wish to "You're going to have to go through me. That's something I would love to see."
The Djinn's purpose is to teach humans moral lessonsThe Djinn's cunning varies pretty drastically. It is always undone by a request that does not appear to be any harder to lawyer into something evil than any previous request. That's because its literally God given purpose, unknown even to itself, is to teach humans virtue. Thus, it is as cunning or stupid as it needs to be to fulfill that purpose, always failing to lawyer a request intelligently once the human has learned her lesson.