The History:
According to Chabapedia (in Hebrew), the flag was first printed in the Hebrew year 5755 (1994-1995) by Yaakov Ben Ari of Tzfat, Israel.
The general design of the flag seems to have originated in flags printed by the World Chabad Center in the 770 for Simchat Torah of 5753 (1992) on which was printed "Yechi Hamelech" (Long Live The King) in Hebrew, but the idea for having a specifically messianist flag, according to this was when Ben Ari, as a young man, went to an anti-Oslo Accords protest in Kiryat Arba and saw someone protesting while holding an Israeli flag. This seemed to him tremendously ironic, to protest the country while holding the country's flag, and so he decided a new flag was needed. Just a few days prior he seems to have seen a sign that had a "beautiful crown" on it, so he took the sign with him and saved it. After the protest, he went to an advertising agency called א.מ. איקס פרסום (A.M. X Pirsum), whose owner was close to Chabad. Ben Ari worked with the agency's graphic designer, deciding to put the crown he liked in the center and the word Moshiach beneath, so everyone will know which king the flag is referring to. Seemingly on a whim, he chose the colors yellow, blue and red, but really it was because he had seen some time earlier a Chabad-Moshaich event in which Chabad sent vehicles all over Israel with signs in those colors that read "Baruch Habah Melech Hamashiach" (Welcome, the King Messiah) (It seems this campaign's color scheme was based off of the flags printed for Simchat Torah, or perhaps they were part of the same campaign).
As noted both by Chabadpedia and the linked article, in the first version of the flag, the crown was red and the text was blue, as can be seen here (the small flag):

After finishing the design, Ben Ari went to receive the approval of a "Geulah-expert" named Rabbi Zimroni Zelig Tzik. With the rabbi, the final text, which included only the word "משיח" (Moshiach) was approved. From there he went to print the first batch of flags, which were first waved in a Chabad march for the Geulah on the 9th of Av of that year in Tzfat. After that, he decided to change the colors a bit because he was told the flag would look even more beautiful that way.
The Design:
According to this site, the flag attempts to fulfill the verse "May we shout for joy in your victory, arrayed by standards in the name of our God. May the LORD fulfill your every wish." (Psalm 20:6) and also represents "our strong will to receive the true face (panim in hebrew refers to pnimiut - interior or profundity) of Moshiach (the Messiah) [which] is the highest expression of divinity within a human being, and the model for humanity to live to the up most of his ability."
The yellow background alludes to sunlight (Shemesh HaVaya - The Eternal Light). The crown alludes to Mashiach "or the Messianic Coronation of Humanity (a human being) provided by God when humanity has achieved it's perfection."
According to the article which brought the story of the flag, many years after the flag was first printed, a man came up to Ben Ari and told him:
"How did you manage to create a flag that hits the target so well?"
"What do you mean?" asked Ben Ari.
"According to Kabbalah," answered the man. "there's a deep meaning to the color yellow, which symbolizes war, as it says "do battle with Amalek" and "צהב" (Tzahov, yellow) is an acronym of that verse (צא הלחם בעמלק)! And of course, the whole reasoning behind the flag is fighting off the cooling-off 1."
The Flag Pin:
The wife of a Chabadnik millionaire named Avi Taub wanted to gift a pin to the workers of her husband's factory, and so called up Ben Ari to design a pin. He originally thought of creating a small cloth pin, but when he went back to the same advertising agency and while waiting for the owner, noticed a row of flag-shaped pins designed for various IDF units, which were made of metal. He requested the pin be made like the Chabad Moshiach flag (and out of metal). At first, many people were afraid to wear the pin on their lapels, because apparently it wasn't very fashionable. But then 9/11 came and after that, President Bush started wearing a USA flag pin on his lapels and many world leaders followed suit and from there, many Chabadniks started to wear their pins.
1 I believe this is a reference to the well-known midrash about the first stand-off between Amalek and Israel, famously brought by Rashi:
"אשר קרך בדרך HOW HE MET THEE BY THE WAY — The word קרך is connected in meaning with מקרה “a sudden happening”, i.e., he came against thee by surprise. Another explanation is: it is connected in meaning with the term קרי, nocturnal pollution and uncleanness, because he polluted them by pederasty. Yet another explanation is that it is connected in meaning with the expression קור in the phrase קור וחום “cold and heat” and it means: he made you cold and lukewarm after the boiling heat you had before. For all the nations were afraid to war against you and this one came and began to point out the way to others. A parable! It may be compared to a boiling hot bath into which no living creature could descend. A good-for-nothing came, and sprang down into it; although he scalded himself he made it appear cold to others (Midrash Tanchuma, Ki Teitzei 9)."