Yankee Doodle Dandy was written by the British to mock the colonists who they saw as inferior. They sang it to call Patriots weak, gay (yes), fools, and never up to snuff with the British.
As the Continental Army won battles through the 1770's, they adopted Yankee Doodle Dandy as a fight song. From Bunker Hill to Saratoga, as American Patriots won battles more handily, they sang louder and more passionately as the British retreated listening to [their] own symbolism turned against them.
Fuck around and find out.
https://youtu.be/5Q0OFPhhv3A
And that's also why patriots used the melody for "God Save the King/Queen" for our informal national anthem, America (My Country 'Tis of Thee) by Samuel Francis Smith. At the end of the song, where the Brits say, God Save the Queen/King, we say "Let Freedom Ring".
A nice FU back to the Crown.