Begining the Game of King and Prophet
The story from here is fun to read, though somewhat forked and muddled. Samuel anoints Saul as 'prince' in a couple of different ways, David comes to be his companion in two different ways, we get different versions of why Samuel concludes that Saul has forfeited God's favor. In any case, Samuel secretly anoints David to be king, while Saul decides that David's popularity makes him a threat to the dynasty Saul would like to found:
"Saul said to [his daughter, David's fiancee] Michal, 'Why have you deceived me thus, and let my enemy go, so that he has escaped?'
"And Michal answered Saul, 'He said to me, "Let me go; why should I kill you?" '
David's popularity keeps him safe, but the struggle becomes ruthless. When Saul learns that Ahimelech the priest has (innocently?) helped David and his followers: "The king said to the guard who stood around him, 'Turn and kill the priests of the Lord, because their hand also is with David; and they knew that he fled, and did not disclose it to me.'... and [though the guards refused, Doeg the Edomite] killed on that day eighty-five persons who wore the linen ephod. And Nob, the city of the priests, he put to the sword; both men and women, children and sucklings, oxen, asses and sheep, he put to the sword.
"But one of the sons of Ahimelech the son of Ahitub, named Abiathar, escaped and fled after David. And Abithar told David that Saul had killed the priests of the Lord. And David said to Abiathar, 'I knew on that day, when Doeg the Edomite was there, that he would surely tell Saul. I have occasioned the death of all the persons of your father's house. Stay with me, fear not; for he that seeks my life seeks your life; with me you shall be in safekeeping.'"
With the surviving priest in his company, David acquires the use of his Urim & Thummim to 'enquire of the Lord' about matters like: "Shall I go up and smite the ____ at ____?[Or not?]" David and his followers survive and flourish through priestly divination, a wealth of cunning, a little extortion, deals with the Philistines, a few massacres, etc., while Saul, lacking the Urim and Thummim to consult, with his kingdom divided in loyalty between himself and David, falls in battle with the Philistines. For awhile there is war between Saul's family and David's, but David prevails, becomes the recognized king of Israel, takes the fortified city of Jerusalem and makes it his capitol-- a place (at the time) outside the territories of any Israelite tribe.
Different tribes remain in intense rivalry, and this may be among the reasons for David wanting to build a national Temple in Jerusalem. But (2 Samuel 7->7.16):
Now when the King dwelt in his house, and the Lord had given him rest from all his enemies round about, the King said to Nathan the prophet, "See now, I dwell in a house of cedar, but the ark of God dwells in a tent."
And Nathan said to the King, "Go, do all that is in your heart, for the Lord is with you."
But that same night the word of the Lord came to Nathan, "Go and tell my servant David, 'Thus says the Lord: Would you build me a house to dwell in? I have not dwelt in a house since the day I brought up the people of Israel from Egypt, but I have been moving about in a tent for my dwelling. In all places where I have moved with all the people of Israel, did I speak a word with any of the judges of Israel, whom I commanded to shepherd my people Israel, saying, "Why have you not built me a house of cedar?" ' Now, therefore thus you shall say to my servant David, 'Thus says the Lord of hosts, I took you from the pasture, from following the sheep, that you should be prince over my people Israel; and I have been with you wherever you went, and have cut off all your enemies from before you; and I will make for you a great name, like the name of the great ones of the Earth. And I will appoint a place for my people Israel, and will plant them, that they may dwell in their own place, and be disturbed no more; and violent men shall afflict them no more, as formerly, from the time that I appointed judges over my people Israel; and I will give you rest from all your enemies. Moreover, the Lord declares to you that the Lord will make you a house. When your days are fulfilled and you lie down with your fathers, I will raise up your offspring after you, who shall come forth from your body, and I will establish his kingdom. He shall build a house for my name, and I will establish the throne of his kingdom forever..."
But in 1 Chronicles 22.7-8: David says to Solomon, "My son, I had it in my heart to build a house to the name of the Lord my God. But the word of the Lord came to me, saying, 'You have shed much blood and have waged great wars; you shall not build a house to my name, because you have shed so much blood before me upon the Earth.' "
Was there an omission from Nathan's speech above? Or does this refer to an incident in 2 Samuel 16, where David and his followers are fleeing Absalom's rebellion:
When King David came to Bahurim, there came out a man of the family of the house of Saul, whose name was Shimei, the son of Gera; and as he came he cursed continually. And he threw stones at David, and at all the servants of King David; and all the people and all the mighty men were on his right hand and on his left. And Shimei said as he cursed, "Begone, begone, you man of blood, you worthless fellow! The Lord has avenged upon you all the blood of the house of Saul, in whose place you have reigned; and the Lord has given the kingdom into the hand of your son Absalom. See, your ruin is on you, for you are a man of blood."
Then Abishai the son of Zeruiah said to the King, "Why should this dead dog curse my lord the King? Let me go over and take off his head."
But the King said, "What have I to do with you, you sons of Zeruiah? If he is cursing because the Lord has said to him, 'Curse David,' who then shall say, 'Why have you done so?'"
And David said to Abishai and to all his servants, "Behold, my own son seeks my life! How much more now may this Benjaminite! Let him alone, and let him curse, for the Lord has bidden him. It may be that the Lord will look upon my affliction, and that the Lord will repay me with good for this cursing of me today."
But later, in 1 Kings 2.8->, David is on his deathbed advising Solomon:
"And there is also with you Shimei the son of Gera, the Benjaminite from Bahurim, who cursed me with a grievous curse on the day when I went to Mahanaim; but when he came down to meet me at the Jordan, I swore to him by the Lord, saying, 'I will not put you to death with the sword.' Now, therefore, hold him not guiltless, for you are a wise man; you will know what you ought to do to him, and you shall bring his gray head down with blood to Sheol."