"The Flag" is simply short for "the flag of the United States of America" -- which, as you can imagine, is easier to say. We use the definite article to indicate the noun is something that is either unique, or already known.
Of course saying "the flag" doesn't imply there is only one valid "flag" in the world. Every country has its own version of "the flag". You have to judge which flag the speaker means from context.
The question on the naturalization exam does raise an interesting point about the ultimate purpose of something like the Pledge of Allegiance. Who are you offering your "allegiance" to? The country as a whole? The President? A symbolic piece of cloth? The laws on which the county is founded? Some combination of all of the above?
But a full discussion of this is probably outside the scope of ELL.