This post here deals with the same question as OP:
Frank Herbert’s Dune Explained and Reviewed
Here goes. The first thing I thought was that Dune was a metaphor for the Middle East.
But I don't think this is it. I believe answer is in the Herbert's own words:
It began with a concept: to do a long novel about the messianic convulsions which periodically inflict themselves on human societies. I had this theory that superheroes were disastrous for humans, that even if you postulated an infallible hero, the things this hero set in motion fell into the hands of fallible mortals. What better way to destroy a civilization, society, or a race than to set people into the wild oscillations which follow their turning over their judgment and decision-making faculties to a superhero?
Timothy O'Reilly writes that Herbert looked into Islam and Judaism for inspiration and, when one analyzes the words, names, titles etc., it shows words inspired by Arabic and Hebrew mostly (Jihad, Kefitzat Haderech).
In fact, Herbert chose Arabic mostly for the superficial reasons:
If you want to give the reader the solid impression that he is not
here and now, but that something of here and now has been carried to
that faraway place and time, what better way to say to our culture
that this is so than to give him the language of that place.... That
oral tool - it has its own inertial forces; it's mind-shaping as well as
used by mind.
O'Reilly also mentions that Herbert's research concluded that Islam fits best into the "periodic messianic convulsions" requirement. I personally see the logic, (albeit only because I remembered how I saw Islam, before I educated myself on it thoroughly), but I disagree thoroughly with these conclusions. Nevertheless, the Islamic inspirations are there, but mostly superficial - far more important to the plot is the society, which, as described by the book, matches more closely with European Feudalism than any other socio-political system, for example.
Regardless of my opinion, however, the Islam setting for Dune - for what it's worth - is a deliberate choice due to the history of this specific religion and region it is associated with - desert - but most of all, for language and association it will create in readers' minds. But Fremen religion is also deeply steeped in ecology and it's science, which offers many possibilities for the story:
I decided to put the two together because I don't think any story
should have only one thread. I build on a layer technique, and of
course putting in religion and religious ideas with ecological ideas
you can play one against the other.
It is difficult to not see how this approach may split the reader audience on the opinion on how to interpret this elements of the story. And while it is entirely understandable to be confused by it and assume it's an allegory of the Middle East, the basic story presented in the book can be found all over the planet...
It is interesting to realize how many similarities there are between Dune and Hamlet, for example. But that's just one of many. The story of a Hero's rise and downfall, as well as his legacy's, can be found in every period and/or civilization, making it just a plot vehicle best suited to achieving Author's goal.