This is an inference, not a fact. In the great renaissance of Florence there were several statues of David made, and the first by Donatello was just within a whole series of biblical figures.
As art historians like to assay:
Since Frederick Hartt's influential essay, "Art and Freedom Quattrocento Florence"," it has been common to understand images of the young David as personifications of Florence's dedication to political freedom or republican liberty; and it has been assumed that David was an official or quasi-official emblem of the city.
Hartt based this interpretation primarily on his reading of the first sculpture in the series, Donatello's marble David. Following the lead of the historian Hans Baron, Hartt argued that Florence's struggles with Milan and Naples at the beginning of the century had profoundly transformed the civic culture of the city, making it the capital of republicanism in Italy. Hence, David, as giant-killer, would have been understood as a tyrannicide and a personification of libertas.
But it is important to realize that this political interpretation of David has been based on an analogy, not on more explicit evidence such as a text or document.
The most probable explanation is that the Medici occupied this symbol of David, for themselves. And since Medici and Florence and renaissance art are often one and the same thing (at least as seen in a certain perspective), that transfer is plausible.
As Alison Brown has suggested, one goal of Medici propaganda was to demonstrate that the family's unique capacity for good government justified their supraconstitutional power. It is known, more-over, that the Medici planned works of art with this propagandistic end in mind. Their patronage of images of David would be fully consistent with this program. Like Donatello's Judith, David personified both humility and divine aid against enemies; and like Vererrocchio's Christ and St. Thomas, David represented clemenc justice and good government.
Andrew Butterfield: "New Evidence for the Iconography of David in Quattrocento Florence", I Tatti Studies in the Italian Renaissance, Vol. 6 (1995), pp. 115-133. (jstor)
It is therefore somewhat correct to assume that the Michelangelo David was not the mascot of Florence. But as the arts developed in parallel, it wasn't that much earlier either.
The Old Testament hero David first became a popular subject in Italian art during the early Renaissance because Florence had adopted him as a type of mascot. Florence was a major center for trade and finance, yet it was relatively small compared to the city-states of Rome, Milan, and Venice, so the city adopted David, who killed the giant Goliath with a slingshot, as a symbol of their city. David is the original victorious underdog.
Take Five: David in Italy, 2012
- Donatello David (marble): commissioned in 1408 and on display since 1416 (as this artwork wasn't popular at all until then (src, discussing the disputed origins of that statue)
- Donatello David (bronze): commissioned by Cosimo de Medici between 1444 bis 1446
- Andrea del Verrocchio David: commissioned by Piero de'Medici 1460-1473
- Michelangelo David: commissioned in 1501 by the arte della lana (of which the Medici were members, as they only later raise to fame with banking)