Because the Messiah's mission was multi-faceted he is represented by many different "types". For example, when David proposed to build a "house" for the LORD God told him that he couldn't because he was a warrior so it must be his son Solomon who builds the house. This was not criticizing David for killing Goliath or anything but rather because Solomon was the proper "type" of Christ, the Temple-builder:
.... But the word of the LORD came to me, saying,
Thou hast shed blood abundantly, and hast made great wars: thou shalt
not build an house unto my name, because thou hast shed much blood
upon the earth in my sight.
In very much of that fighting David had been faultless; for he fought the battles of the people of God. Still, there are some things
that men are called to do, for which they are not to be condemned; but
they disqualify them for higher work. It was so in David's case; he
had been a soldier, and he might help to build the temple by
collecting the materials for it, but he must not build it. 9.
Behold, a son shall be born to thee, who shall be a man of rest; God's Church is to be a place of rest. God's temple was built by "a
man of rest."
9. And I will give him rest from all his enemies round about: for his name shall be Solomon, and I will give peace and quietness unto
Israel in his days.
Then the house of the Lord would be built; no stain of blood would be upon it. The only blood therein should be that of holy sacrifices,
symbolical of the great Sacrifice of Christ...
David was in many, many ways a type of Messiah as a rejected king.
Jesus did not come to be the king of Israel. He came to be rejected as king! God had hardened the leadership as predicted in the prophets.
There used to be a TV show similar to "The Twilight Zone" called "The Outer Limits". Like all "ancient" TV shows the special effects were minimal, and to modern viewers, laughable but at the time the show was "credible". Anyhoo, there was an episode in which a spaceship lands and broadcasts "We come in peace, do not harm us". However, the Army gets all freaked out and kills them all even though they didn't do anything. Spoiler Alert: Then they reveal that they didn't have capital punishment on Zanti but these were dangerous criminals that had to be killed and they were sent to earth because they knew they were killers.
[Mat 17:23 KJV] 23 And they shall kill him, and the third day he shall be raised again. And they were exceeding sorry.
[Mat 20:19 KJV] 19 And shall deliver him to the Gentiles to mock, and to scourge, and to crucify [him]: and the third day he shall rise again.
[Mar 10:34 KJV] 34 And they shall mock him, and shall scourge him, and shall spit upon him, and shall kill him: and the third day he shall rise again.
[Luk 13:32 KJV] 32 And he said unto them, Go ye, and tell that fox, Behold, I cast out devils, and I do cures to day and to morrow, and the third [day] I shall be perfected.
[Luk 18:33 KJV] 33 And they shall scourge [him], and put him to death: and the third day he shall rise again.
[Luk 24:7 KJV] 7 Saying, The Son of man must be delivered into the hands of sinful men, and be crucified, and the third day rise again.
Also, the Messiah is typified by his not even considering coming to the throne by violence but rather by resolute obedience to God:
[1Sa 24:6, 10 KJV] 6 And he said unto his men, The LORD forbid that I should do this thing unto my master, the LORD'S anointed, to stretch forth mine hand against him, seeing he [is] the anointed of the LORD. ... 10 Behold, this day thine eyes have seen how that the LORD had delivered thee to day into mine hand in the cave: and [some] bade [me] kill thee: but [mine eye] spared thee; and I said, I will not put forth mine hand against my lord; for he [is] the LORD'S anointed.
[Psa 75:6-7, 10 CSB] 6 Exaltation does not come from the east, the west, or the desert, 7 for God is the Judge: He brings down one and exalts another. ... 10 "I will cut off all the horns of the wicked, but the horns of the righteous will be lifted up."
So too the Messiah could have (and was expected to) overthrow Rome and Herod and set himself up as king. But instead we see the Messiah refusing kingship by force:
[Jhn 6:15 KJV] 15 When Jesus therefore perceived that they would come and take him by force [ἁρπάζω], to make him a king, he departed again into a mountain himself alone.
Common Taters often think that the crowd was going to force Jesus to be king but as I see it they wanted to use physical violence to make him king, which he refused to be a part of.
The word used in John 6:15 to say "by force" (ἁρπάζω) is the same word used in Philippians 2 when Paul says that Jesus did not contemplate or even consider seizing (ἁρπάζω) his reign by God's right hand:
[Phl 2:5-11 KJV] 5 Let this mind be in you, which was also in Christ Jesus: 6 Who, being in the form of God, thought it not robbery [IE: did not consider seizing the throne by force, ἁρπάζω] to be equal with God: 7 But made himself of no reputation, and took upon him the form of a servant, and was made in the likeness of men: 8 And being found in fashion as a man, he humbled himself, and became obedient unto death, even the death of the cross. 9 Wherefore God also hath highly exalted him, and given him a name which is above every name: 10 That at the name of Jesus every knee should bow, of [things] in heaven, and [things] in earth, and [things] under the earth; 11 And [that] every tongue should confess that Jesus Christ [is] Lord, to the glory of God the Father.
But finally, and this may be the most straightforward matter for the current question, just being anointed does not actually make you king. That is, Jesus was anointed (with the actual, not symbolic, anointing with the Spirit and yet never became Israel's king because they refused him. He was "anointed" but never reached Israel's throne. Instead, he was refused, killed, exalted, received the Spirit and anointed a whole generation of the last days Jews:
[Isa 10:27 KJV] 27 And it shall come to pass in that day [IE: in the age of the Messiah], [that] his burden shall be taken away from off thy shoulder, and his yoke from off thy neck, **and the yoke shall be destroyed because of the anointing.
[1Jo 2:27 KJV] 27 But the anointing which ye have received of him abideth in you, and ye need not that any man teach you: but as the same anointing teacheth you of all things, and is truth, and is no lie, and even as it hath taught you, ye shall abide in him.
So to recap, David was a type of Christ, particularly in the aspects of his kingship and in particular, several chapters of his being "on the run" as he waited for God to act to establish him on the throne without him getting his hands dirty.