God is sovereign. He allows rulers to be installed in order to accomplish His purposes. His purpose may be to bless those who trust Him, or even to correct those who go astray. Sometimes he lets people have their own way to teach them a lesson. This happened in Israel's history when they wanted a king. It also occured during Moses' time.
So he gave them what they asked for,but sent a wasting disease upon them.
Psalms 106:15 - NIV