It was not inevitable, but resulted from a series of decisions taken by the Shah. The Shah could have made different decisions that allowed the monarchy to survive, although very likely more and more power would have gone to the Majlis and Iran become a parliamentary democracy with a constitutional monarch.
The major problem for the Shah is that he did not have an extensive base of political support. He had the large landowners, but they were very small. For most of the period in his reign, he could also rely on the merchants of the Grand Bazaar, the conservative clergy, and westernizing (but not the liberal elite) middle classes, but he alienated both of them by the late seventies. This was an unwieldy coalition at cross purposes, and the Shah pulled a trifecta by having all of them oppose him.
He lost the conservative clergy early on. They were glad to see Mossadegh go and the Tudeh kept out of power, but the rise of Western cultural influence meant that this group ultimately would not be on his side.
Much of the Shah's economic reforms meant the middle class was growing, but the middle class always expects to have a say in the how they are governed, and this the Shah refused to do. So the biggest mass group that should have supported his modernizing efforts ended up becoming his opponents. Some kind of modest political concessions should have happened. Instead, as the Shah got older, he centralized even more power and eroded what little role the Majlis and middle classes had.
Even with all of this loss of support, the Shah still retained enough old time legitimacy that he could ignore political pressure - but only when the economic times were good. They were for most of the Shah's reign in the 1950s to early 1970s. However, the Shah made a critical error during the Oil Crisis.
Iran was making enormous money from oil sales, and the Shah wanted to invest everything all at once to make Iran a first world economy within a generation. All of his economists said this was a mistake because 1) it was uncertain if oil prices would continue to be high, and Iran should save most of the money as a reserve, 2) it would overheat the economy and cause massive inflation by investing so much money so quickly when the nation lacked the capacity to handle such stimulus, and 3) by investing in so many projects, if oil prices did decline, the state would need to cut off so much funds that it would create massive unemployment and hardship. The Shah ignored their advice, and what they feared happened.
At that point, the politically neutral portion of the middle class become radicalized, and the Teheran bazaar merchants came out against the Shah.
It was this combination that brought the Iranian Revolution. At the time, almost everyone thought the end result would be a liberal democratic Iranian republic controlled by the democratic opposition parties. However, Khomeini was very smart and cunning and used every opportunity to hijack and revolution and institute an Islamic dictatorship.
I believe if the Shah listened to the advice of his economists, he would have stayed in power. He was not going to live long anyway, and after he died, I suspect the crown prince would have conceded enough political reforms to pacify the democratic opposition to keep the monarchy on the throne. There would be continued turmoil to some extent until the new Shah allowed real constitutional reforms, but I don't see why the Shah could not have followed Taiwan's and South Korea's path by eventually establishing a true democratic government by the early 1990s.