This is another of those interesting things in the Bible for which we aren’t given a reason, so we can take an informed guess. One of the best suggestions is that David took five stones, one for Goliath, and one for each of Goliath’s infamous relatives: Ishbi-benob, Saph, Goliath and someone identified as ‘a man of great stature, who had six fingers on each hand, and six toes on each foot, twenty-four in number’ (2Sam. 21:15-22). These were all, like Goliath, ‘descended from the giants’.
These enemies of Israel weren’t killed until later in David’s life (see 2Sam. 21), but it shows David’s courage and, more especially, his trust in God (1Sam. 17:37) that he was prepare to confront not only Goliath, but also Goliath’s relatives. We are encouraged by this to have the same trust in God to confront all the difficulties we — and other of God’s people — face in life.
Another, less attractive, possibility is that David took five stones in case he missed a few times. A lesson we could learn from this is that, although God will bring victory for his people, the battle might be long, with ups and downs.