I would think “it” refers to the feather. The pony is too far away in the sentence (as is the hat).
Grice’s cooperation principle states: “Make your contribution such as it is required, at the stage at which it occurs, by the accepted purpose or direction of the talk exchange in which you are engaged.”
This is an idea in linguistics that by adding or witholding information relevant to the conversation, you can change the meaning that someone will take from it. If Grice’s principle was correct (I’m not sure about the evidence for it), and the writer of Yankee Doodle had intended us to think of the horse s/he could have said something like:
“He took a feather from his hat and called his pony macaroni.”
But s/he didn’t. Why? Either because the more straightforward reading was intended, or because they were trying to make a funny (but subtle) point about linguistics.
Off topic, but my favourite example of how context changes meaning is this: “time flies like an arrow, fruit flies like a banana”.
Ha ha ha! I found the answer to this:
“Macaroni” was a fancy (“dandy”) style of Italian dress widely imitated in England at the time. By sticking a feather in his cap and calling himself a “dandy,” Yankee Doodle was proudly proclaiming himself to be a gentleman of some social standing.