Ezekiel 34 uses the metaphor of a shepherd for the kings of Israel. What is the origin of that metaphor? David?
Shepherd is a common figure for the ruler in the Ancient Near East so it wouldn't originate with David. Since David had been a literal shepherd, one wonders if at times there might be a play on the former shepherd of sheep being now the king, who is a shepherd. For example in a passage I was reading recently in my devotions, in 1 Chronicles 17.6 the judges of Israel are described as shepherding the people. V. 7 goes one to speak of David as one who was following the sheep when God called him to be the leader over the people.
Clearly the image of the shepherd pervades OT literature, appearing no fewer than 90 times. It is an image that appears prominently in the Psalms, of course, leading to the easy conclusion that it dates back at least to the time of David. In 2 Samuel, further, reference is made to the king being shepherd over Israel (2 Sam 5:2, 7:7). In the historical books, the same metaphor is used in 1 Kg 22:17; 1 Chr. 11:2, 17:6; and 2 Chr. 18:16. Hence Ezekiel is appealing to a metaphor that already has currency in the imagination of his listeners, particularly as a prophet who appeals to their sense that they have been led 'astray.'
The ideal of the good "shepherd king" is a very ancient Near Eastern concept, dating back to even before biblical times. As Jack W. Vancil writes, "Throughout Mesopotamian history, the shepherd image was commonly used to designated gods and kings; and as a title for kings this use is attested from practically every period....The king as a shepherd and as a representative of the gods was expected to rule with justice and to show kindness in counseling, protecting, and guiding the people through every difficulty" (Anchor Bible Dictionary , s.v. "Sheep, Shepherd," here vol. V p. 1188; for earlier discussions, see articles "Sheep" and "Shepherd" in Interpreter's Dictionary of the Bible  and in Harper's Bible Dictionary .)
This image was picked up by the biblical writers and applied to God in the Old Testament and Christ in the New Testament as the true "shepherd king" of his people, and also to kings as an ideal to which they should measure up but all too often--as in Ezechiel 34--did not.
The durability of this image is shown by the title of W. A. Mozart's 1775 opera Il Re Pastore, "The Shepherd King."
The image/metaphor is commonly used for kings and gods throughout the ancient Near East from at least the third millennium BC. Obviously, the image emerges from agricultural life and the knowledge of the relationship between sheep and shepherd.
The image of a king as shepherd is older than the Bible and Hebrew tradition itself. It is part and parcel of the metaphors for a king (others include "Father," "Warrior," and "Sage") throughout the ancient Near East and it attested in Mesopotamian texts from a millennium before the Bible began to be written.
The shepherd image is the ancient way that monarchs communicated, "I feel your pain." The focus of the image is on the care and protection the shepherd offers the flock. Ancient monarchs were no different than contemporary political leaders: however self-serving their motives, they wanted their constituents and subjects to imagine that they personally cared for them.
The metaphor of shepherd was applied to both gods and kings in the ancient near east and Egypt before Israel emerged on the scene.
Given that the occupation of shepherd was not prestigious and usually left to teenagers, the poor or the elderly, it is indeed a puzzling one to apply to rulers. Male shepherds were usually on their own, away from other human beings. The notion that shepherds developed leadership skills that would be useful in the human community is unrealistic. There are, however, parallels that are notable. Shepherds very often cared for sheep that were not their own. So the kings of Israel were to care for people who were not their own; they belonged to God. The shepherd drives the sheep to hillsides and valleys where there is food and water for their sustenance. The sheep could, perhaps, find food on their own without the assistance of a shepherd. But the shepherd makes it easier. These are two ways in which Israelite kings were like shepherds.
The shepherd metaphor appears in 2 Samuel 5:2 where the Israelite people say to David “Yahweh said to you, you will shepherd my people Israel and you will be a leader over Israel.” (Translation my own.) Notice that the Israelites do not say, “Yahweh said to us….” They are repeating what David told them. I translated the text myself because I want to maintain the sense that “shepherd” is used here as a verb not a noun. David is not told that he will be a shepherd but that he will shepherd the Israelites. What he will be is a nagid which means a ruler though not necessarily a king. Leaders of tribes that constitute Israel are also said to shepherd their folk (2 Samuel 7:7). Importantly, the people of Israel are God’s people, not David’s people.
It is significant that the king as shepherd metaphor also appears in prophetic texts in Ezekiel and Jeremiah, both late books written after the end of the independent Israelite kingship. In Ezekiel and Jeremiah, the complaint is that the kings of Israel did not shepherd the people.
God is given the title shepherd in the poem in Genesis 49:24. This is a very old poem and probably the earliest use of the metaphor in the Bible. Here the word “shepherd” is connected to many titlesfor God but “king” is not one of them.