David being David was the result of God’s faithfulness.
“God delivered David from the danger of having to fight against the Israelites, who were God’s people. There was no way that David could extract himself from that situation by his own means, but God prevented him from becoming an enemy of Israel by using the commanders of the Philistines. Even now, God can save those of us who have fallen into a situation where there is no way out. Before we say that there is nothing to be done, let us trust in God without regret.”