Look at what this is saying: it is a prophecy, a prophecy that came true.
When you arrive there... and say, “I want a king over me, like the other nations have,” you will have a king, one whom God will chose from among you all; you will not be allowed to have a foreigner as a king.
Keep in mind that a lot of biblical prophecy is not about “telling the future” but about God specifically bringing something to pass b/c He wants it to come to pass (sounds similar, but two somewhat different concepts here). The fact that God made a law to regulate the monarchy shows He intended for them to have a monarchy. It wasn’t some accident that God had to suddenly come up with a fix for.