It may seem an obvious metaphor to us now, but why? After all, Israel didn't always have kings. Not only that, but the Book of Samuel makes it clear that in God's opinion Kings are a Very Bad Idea, and that the Israelites' demand for them is foolish at best, and maybe only a slight improvement on the fad for golden calves (1 Sam. 8). Nor did the idea get off to a great start, with the very first king, Saul, being cursed for his lack of thoroughness over the genocide of the Amalekites. Yet the office stuck, and no one from David onward seriously thought about going back to the good old days of the Judges.
So, at some point God starts being referred to with royal imagery. I'm not well enough versed in the scholarship to know the current state of opinion about which parts of the Old Testament were written when - but is there much talk of God-as-King in the Pentateuch, for example? Come to that, is there much talk of him as a father? Again, it seems an obvious metaphor - but perhaps that's because it's so familiar (and obviously it's everywhere in the Gospels). My memory of the early parts of the Bible is shaky, but for the most part I recall God being described simply as God, with no need for human-based metaphors at all.