While being a royal king, David also operated in the prophetic, as noted by the Psalms he wrote that foreshadow Jesus. Even Jesus Himself acknowledged David’s ability to write things “in the Spirit” (Mt 22:43). David also speaks to his prophetic gifting in his last words, saying,
“The oracle of David, the son of Jesse,
the oracle of the man who was raised on high,
the anointed of the God of Jacob,
the sweet psalmist of Israel:
“The Spirit of the Lord speaks by me;
his word is on my tongue. (2 Sa 23:1-2)
This may confuse us at first, because we wonder how a king might also be able to operate as a prophet. The answer is in the fact that, like the prophets, sometimes the kings of Israel operated out of the endowment of the Holy Spirit and so there could be overlap. As John Walton notes,
Prophets and kings received overlapping manifestations of divine endowment, but for prophets the emphasis falls on the spoken word (cf. Num. 24:2; 2 Sam. 23:2; Isa. 59:21; Joel 2), while for kings the emphasis falls on actions. (Walton, John H. “The Ancient Near Eastern Background of the Spirit of the Lord in the Old Testament.” Presence, Power and Promise. Kindle Locations 553-554.)
But apparently for David, the Spirit worked in both ways in his life. Though this isn’t to say that the kings always operated out of the Spirit. As God points out through the lips of Hosea, “They made kings, but not through me. They set up princes, but I knew it not” (Ho 8:4). Therefore, simply being a king clearly does not equal divine appointment and the gifting of the Holy Spirit.
But outside of a few good Kings, there is a pretty harsh line in Israel when it comes to roles. God’s ability to relate to Israel has now been divided between the (1) royal king, (2) the lowly prophets, and (3) the priesthood. Sometimes these roles overlap, but many times they are entirely separate.