It is somewhat curious that God allowed Israel to have a king. After all, God wanted the Israelites to see him as their king; that's what made them unique from all of the other nations around them. So if it clearly was not in God's will (i.e. it wasn't his desire) for Israel to have a king, why did he allow it? That's a tough concept to grasp. I've heard it explained that God has a Sovereign Will, a Moral Will, and a Permissive Will.
God's Sovereign Will is ultimately what happens. We can't know the Sovereign Will until after something has happened. We can look back and see God's Sovereign Will, but we can't look forward and see it.
God's Moral Will is what he desires to have happen. These are the standards that are woven throughout the entirety of scripture. God's Moral Will is composed of the Ten Commandments and the imperatives that he gives to his followers.
God's Permissive Will is what he allows to happen in the world. This is where our free choice comes into play. God's Moral Will was that Israel would look to him as their king, but because of his Permissive Will, he allowed Israel to do things outside of what he truly desired for them.
Ultimately, God's Sovereign Will reigns. I don't quite understand how my choice matches up in all of this, but God allows us to choose in the midst of his ultimate authority. In the end, all that takes place is as He permits.