By giving David command of a unit, Saul would reduce David’s influence at court.1 It also served to spare Saul from shame and retribution if, in a moment of weakness, he should actually kill David with a spear. Finally, it also put David into positions of danger where he could potentially be killed (1 Samuel 18:17). It was very possible that his advisors and officials suggested this course of action to him. They would have been witness to his spear throwing and may have wanted to protect their champion from their king.
13 So Saul removed him from his presence and made him a commander of a thousand. And he went out and came in before the people.