The One And Only Time Star Trek: The Original Series Showed The Federation Flag
Because "Star Trek" is set in a presumably idyllic future — when war is at an end, money has been removed from the equation, and diplomatic togetherness rules the day — one will see few open displays of tribalism or jingoism. No one in "Star Trek" can yell about how much they love their country because, functionally, there are no countries. At least not on Earth. Occasionally, Chekov (Walter Koenig) will express pride, or even smugness, about his Russian heritage, but his attitude couldn't be read as "patriotism." Instead, he has become a smaller part of a large human tapestry, now united and working together to explore the galaxy, expand knowledge, and share ideas.
Perhaps ironically, the widespread multiculturalism of the United Federation of Planets is dressed in military uniforms and sails about the heavens in starships armed with phasers and photon torpedoes. "Star Trek" has all the visual trappings of tribalism while constantly preaching anti-colonialist philosophies. This may be why one doesn't see a lot of flags in "Star Trek." Characters don't pledge allegiance to a flag in "Star Trek," but make oaths to protect all life, keep fighting to a minimum, expand their knowledge, and uphold the open-minded progressive ideals of Starfleet. It's no mystery why the Starfleet "delta" symbol points upward.
There is a flag for the United Federation of Planets, but it was only on-screen in one episode of the original series: "And the Children Shall Lead" (October 11, 1968). Weirdly, the episode has nothing to do with the workings of the Federation, nor intergalactic politics. One cannot say why the UFP flag was employed here.
The Star Trek flag for the United Federation of Planet
"And the Children Shall Lead" is actually about a group of kids, all under 12, who have been manipulated by a charismatic ghost alien (played by real-life lawyer Melvin Belli) into murdering their parents and, later, taking over the Enterprise. The episode's early scenes see the children obliviously playing tag among their parents' graves, and one of them knocks over a UFP pennant. Captain Kirk (William Shatner) hoists it up and replants it in the dirt.
The UFP pennant would be the only on-screen Federation flag in "Star Trek" until "Star Trek II: The Wrath of Khan" in 1982. Naturally, enterprising fans would make their own pennants, and expanded universe lore and nerdy sourcebooks would have plenty of diagrams explaining the pennant and its meaning. In Joseph Franz's 1975 book "Star Trek Star Fleet Technical Manual," the pennant was sketched out in detail, but in black and white, explaining that the lettering should be white and the stars should be silver. This color description, as one can see above, doesn't match the on-screen version from "Children." There is no explanation as to why there are 13 stars on the pennant, as the Federation was founded by four worlds: Earth, Vulcan, Andoria, and Tellar.
In the episode "The Ultimate Computer" (March 8, 1968), an eagle-eyed Trekkie might notice the UFP pennant painted on the exterior of a Federation space station, but know that it was added digitally when the effects for the episode were remastered. "Children" came later in the series, but is still the first appearance of the UFP flag.
The flag on Spock's coffin
The Federation flag from other episodes of "Star Trek" were, by the admission of the showrunners, merely the UN flag, usually filmed in such a way as to be obscure. In "Wrath of Khan," however, the crew of the Enterprise holds a full-blown funeral for Spock (Leonard Nimoy), and, in military fashion, they drape his coffin in a Federation flag. As one can see, the flag was now rectangular, blue, and emblazoned with a starfield and a laurel wreath, or olive branches.
A similar version of that flag would appear a few years later on "Star Trek: The Next Generation," showing that the Federation logo was now a globe-like starfield with laurels on either side of it. That UFP symbol would appear frequently throughout '90s Trek as it would appear on screens after top-secret communiqués. The laurels/olive branches presumably stood for peace.
Weirdly, in the 2013 film "Star Trek Into Darkness," the alternate universe UFP flag would still feature the starfield and the olive branches, but the starfield was superimposed over a "cogwheel"-shaped gear-like image. Around this time, the UFP flag started to be handled like an American flag at military functions, not only draped over officers' coffins, but meticulously folded and handed to others as a symbol of mourning and respect. The folding took place in the "Star Trek: Discovery" episode "All is Possible" (November 9, 2021).
Trekkies, meanwhile, are perfectly fine to spend their mid-capitalist dollars on "Star Trek" merch slathered with the UFP flag. My current mousepad sports the logo. "Star Trek" may be above jingoistic devotion to a flag, but we here back in the 21st century still love to let our fan flags fly.