That verse is generally viewed as a gloss by a later editor. The story of David's confrontation with Goliath has clearly been heavily interpolated and redacted, as is evident when comparing the MT (Masoretic Text) with the LXX (Septuagint) and the Qumran (Dead Sea Scrolls) text, as well as from observing the many odd features of the text shared by them all (which constitute older glosses). It is clear that the Philistine giant wasn't named Goliath in the original version. Even the giant's height increases with later retellings of the story! Here is an older post of mine on the subject:
-----------------------------------------------------
It is generally accepted that the story of David and Goliath in 1 Samuel 17 MT is a relatively late reworking of an earlier story of a confrontation between David and an originally unnamed Philistine. The oldest recension of the LXX omits 17:12-31, 50, 17:55-18:5, 18:17-19, and this material has a different literary style than the other verses and introduces David as a new figure entirely (see v. 12-13 especially) -- suggesting that the interpolated material came from an originally independent story about David (cf. also the doublet between v. 4-9 and v. 23). In this material, the opponent is simply known as "the Philistine" and only in v. 23 is he identified with Goliath of Gath in a gloss that rudely interrupts the sentence: "While he was talking to them, the warrior (His name was Goliath, the Philistine from Gath) came up from the Philistine ranks and made his usual speech, and David heard it". The more original form of the story in 1 Samuel 17:1-11, 32-54 also refers to the opponent only as "the Philistine" except for another awkward (and extravagent) gloss in v. 4-7 which separates the warrior's "stepping out from the ranks" in v. 4 from his "taking his stand" in v. 8:
Probable original version: "One of their warriors stepped out from the Philistine ranks and he took his stand in front of the ranks of Israel" (v. 4a, 8a).
Interpolated version: "One of their warriors stepped out from the Philistine ranks (His name was Goliath from Gath, he was 4 cubits and one span tall. On his head was a bronze helmet and he wore a breastplate of scale-armor; the breastplate weighed five thousand shekels of bronze. He had bronze greaves on his legs and a bronze javelin across his shoulders. The shaft of his spear was like a weaver's beam, and the head of his spear weighed six hundred shekels of iron. A shield-bearer walked in front of him) and he took his stand in front of the ranks of Israel" (v. 4-8a)
This gloss predates the interpolation of v. 12-31, 55ff, as it is found in both the MT and in the LXX, although the warrior's height has been reworked in the various editions, from 4 cubits in 4QSam a and the original LXX used by Josephus, to 5 cubits in the later text of the LXX, to 6 cubits in the MT. Verse 32 is also the natural continuation of v. 11: "When Saul and all Israel heard these words of the Philistine they were dismayed and terrified, | but David said to Saul, 'Let no one lose heart on his account; your servant will go and fight this Philistine.' " The whole block of v. 12-31 interrupts this. Verse 50 appears to be another minor gloss, interrupting the narrative action to spell out what had just happened. It is also not found in the LXX, which goes straight from v. 49 to v. 51. In short, the oldest form of the story consisted of 17:1-4a, 8-11, 32-49, 51-54 and then the gloss in v. 4b-7 was added (which identified the anonymous Philistine warrior with the famous Goliath). The same hand possibly added v. 54 as well (since the addition of this verse predated the LXX). Then in a development limited to the ancestor of the MT, material from an originally independent version of the same story (v. 12-31, 55ff) was added to the text of 1 Samuel 17 and minor glosses like v. 50 were added as well.
The writer who added the gloss in v. 4b-7 would have then took the name "Goliath" from the story in 2 Samuel 21:19 which says that Goliath was slain by "Elhanan, the son of Jair, the Bethlehemite". The extravagent description of Goliath's armor would then have been inspired by such descriptions as those in 2 Samuel 21:15, which describes another Philistine warrior's spear as "weighing three hundred shekels of bronze", and the description of Goliath's spear in v. 19 as having a "shaft like a weavers' beam". The fact that the hero is described as a "Bethlehemite" is also a point of contact with the Davidic story in 1 Samuel 17 as well. But the text of 2 Samuel 21:19 is problematic as well. The MT refers to Elhanan the son of Jair-Oregim whereas the parallel in 1 Chronicles 20:5 (the earliest witness to the text of 2 Samuel) refers to Elhanan the son of Jair. It is clear here that a copyist duplicated the word for "weavers" ('rgym) later in the same verse and misplaced it right after "Jair" (y`ry). Thus "Jair" and not "Jair-Oregim" (which is an odd name in Hebrew) is the name that occurs in 1 Chronicles and the older form of the LXX (which gives the name as Iare). It is in the later (hexaplaric) version of the LXX where the copyist error appears in the form Ariórgim (< Hebrew y`ry 'rgym), and since the late LXX text assimilates itself generally to the proto-MT text, this shows that the copyist error that produced the MT form of the text had already occurred by the third century AD.
Meanwhile, the version in 1 Chronicles has a copyist error of its own. In 2 Samuel 21:19, regardless of whether you consult the MT or LXX, Elhanan was a Bethlehemite (bytlchmy) who killed Goliath ('t-glyt), but 1 Chronicles 20:5 states that Elhanan killed Lahmi ('t-lchmy) who was the brother of Goliath ('chy glyt). The Chronicler here mistakes the word byt- (Beth-) as the inflection for direct object 't- and thus takes the remainder of the name bytlchmy (i.e. -lchmy) as a proper name, i.e. Lahmi. Meanwhile, the 't- inflection in the source was mistaken as the word for "brother" ('ch), making the Philistine the brother of Goliath, and not Goliath himself. Many of the Chronicler's departures from the Deuteronomistic History are ideological in nature, and there may be a motivation here to resolve the contradiction in 2 Samuel 21 by making Elhanan kill the brother of Goliath and not Goliath himself. Such a motivation presupposes that David had already been identified as Goliath's slayer. That would mean that the interpolation of v. 4b-7 in 1 Samuel 17 (which is found in all extant versions of the text) predates the composition of 1-2 Chronicles, and thus had already occurred before the fourth century BC. Or it could be that the interpolator of 1 Samuel followed the Chronicler in allowing himself to identify the slayer of Goliath as someone other than Elhanan (who for the Chronicler was not the slayer of Goliath). It is noteworthy that the LXX version of 2 Samuel 21 (which should go back to the third or second century BC) had an underlying btylchmy in its Vorlage, as it designates Jair as ho Béthleemités "the Bethlehemite", and there is no evidence anywhere in the textual tradition of 2 Samuel itself along the lines of "Lahmi the brother of Goliath". So here is an example of a text paralleled in two works (1-2 Chronicles being literarily dependent on 1-2 Samuel) which is corrupted in both.