Disclaimer: I'm using a book that was published in 2002 for this, and I haven't checked all the flags for consistency, but to my knowledge, none of them have changed. The book was published with The Flag Institute, the leading vexillological organisation in the world.
There are 31 countries in the world(I counted) that have flags made up of the colours red, white and blue. There are more that use only two of these, but I'm assuming you mean the three as a trio.
By region, the divisons are thus:
North America, 1 (United States).
Central America, 3 (Panama, Dominican Republic, Costa Rica).
South America 2 (Chile, Paraguay).
Africa, 2 (Cape Verde, Liberia).
Europe, 12 (Iceland, Norway, Netherlands, United Kingdom, France, Luxembourg, Czech Republic, Slovakia, Slovenia, Croatia, Serbia, Russia).
Asia, 9 (Thailand, Myanmar, Laos, Cambodia, Taiwan, Philippines, North Korea, South Korea, Nepal).
Pacific, 3 (New Zealand, Australia, Samoa).
As you've probably guessed from looking at this list, there's a wide range of nations there, and not all of them have connections with each other, or even with another country listed. To find out why those colours are popular, you would have to delve into each nation's history, as well as taking a look at colour theory. For example, green is a colour found in the flags of almost all Islamic nations, as it is associated with Islam. In Africa, red, black and green are commonly found together representing Pan-Africanism. In other contexts, green is used to represent agriculture, while red is used for courage, communism, or strength. Across regions, colours have different meanings.
Norway's current flag, for example, has been in use since 1821. It takes influence from at least three other flags: the blue of Sweden, from the union between the two nations; the red of Denmark, from that union; and the red, white and blue of the tricolour of France, which became a symbol of freedom and liberty after the revolution. In turn, these three nations have their own flag origins. Denmark's red flag with a white Scandinavian cross is attributed by legend to a vision seen by a Danish King. In actuality, historians have different views. Wikipedia has about six suggestions. The book I'm using favours the theory that the flag was gifted to the Danes by a Pope during the Crusades. The Swedish flag is likewise attributed in myth to a vision of a cross in the sky, hence the gold on blue. In actuality, the colours are likely adopted from the coat of arms of Sweden: "three gold crowns in a blue field - which originated in the 14th century". France's flag first appeared during the French Revolution(I'm holding my breath that I don't get corrected on this). The colours have multiple associations. White was the colour of the Bourbons, red and blue the colours of Paris. But they also represent the French ideals of the revolution: liberty, equality and fraternity.
So in Norway's flag(which I picked because it was the page the book opened to when I needed an example), we have origins for all the colours. Blue, comes from the union with Sweden, remembering national allegiances, and in turn, from the Swedish coat of arms(and if you like mythical origins, a vision in the sky). Red also represents a union, this time with Denmark, and potentially originates with a flag gifted to the nation during the Crusades by the Pope. White likewise recalls the union with Denmark. Old allegiances are the primary reasoning here. Secondary to those is that of freedom, deriving from the French Revolution.
Other countries have fairly obvious links. The United States flag adopted the colours of the United Kingdom in its first form, and kept them when it became the Stars and Stripes. These also came to represent freedom and revolution, much like the French tricolour. Australia and New Zealand recall the UK on their flags too, both with representation of the Union Jack in the canton, and the colours of the stars and background, but with none of the revolutionary links.
North Korea and South Korea share the same colours, because they hark back to the Imperial flag of Korea. On the North Korean flag, the red is now accompanied by a star for Communism and revolution.
The flags of Paraguay, Cuba, Chile and the Dominican Republic are also linked to freedom, but by different paths. Chile based its flag on the Stars and Stripes, but attaches local meaning to the colours - blue is the Andean skies, white the Andean snows, and red represents the freedom struggle. Paraguay's flag dates from the 1811 revolution, and takes the tricolour as a base and influence. Cuba, attempting to become a state of the United States in the mid-19th century also adopted the Stars and Stripes. The Dominican Republic took its colours from Haiti's flag - another national union. Haiti in turn took red and blue from its French origins, albeit, the revolutionary side.
In Eastern Europe, many countries use the red, white and blue as pan-Slavic colours. This origin is commonly tracked to Russia, and prior to that, the colours of the Tsardom of Muscovy. Consequently many of these nations retain them as a signifier of ethnic heritage.
As a final note, some flags had minimal contact with these largely European origins. Cape Verdedesigned its flag in 1992, with blue for the ocean, white for peace and red for progress. Myanmar uses red for courage, blue for peace, and white for purity changed its flag in 2010, as I discovered when I went to find a pretty picture. Yay Myanmar! In Thailand, white is for the purity of Buddhism, and red for life blood. The blue was only added during WWI to "express solidarity with the Allies, whose flags were mostly red, white and blue."
So in conclusion, most countries use these colours either to hark back to unions with other countries(Haiti + Dominican Republic, Norway + Sweden/Denmark, UK + NZ/Aus), or to remember revolutionary ideals of freedom(France, USA, Chile, Paraguay). But it's important to remember that within these ideals of revolution and solidarity, each country often has its own reason for those colours being important. Whether it be white for peace, or blue for oceans, the colours generally have multi-layered meanings.
EDIT: See this comment for a bit of info on the influence that the Dutch flag had on flags of Europe too, specifically the Russian flag.
EDIT 2: /u/MiffedMouse pointed out I forgot Nepal! Added it now. Nepal also uses blue as a symbol of peace, much like Myanmar's previous flag. I wonder if it's a South East Asian convention to use blue as a representation of peace. Possibly because it contrasts so much with red, the colour of war and blood?
EDIT 3: Gold? You're so kind!
It's very interesting to see this posted, as I was actually wondering the same thing earlier today. Here are a couple of links to similar questions that have been asked on reddit before.
I am curious about the prevalence of the color blue on flags, which seems to show a small regional variance. Is that the result of the variable availability of blue pigments when the institution of flags spread? Or one of historical coloring patterns across the globe? Is there another explanation?
/u/LordHussyPants answered so well I hesitate to add anything. But there's this other thing: Why?
I like WHY questions a lot but history seems more the study of what happened. The colors R/W/B as used by humans didn't arrive from nowhere. Colors are actually some of our species' earliest technologies--and the colors Red and Blue in particular were hard to find. They were precious because of scarcity. The best example of the scarcity of the technology creating symbolic importance is ^^(tyrion) Purple, but blues and true reds were also highly prized.
The question before flags is this: Why did early civilization choose symbolic meanings for R/W/B? Answer: Scarcity in combination with a need for ubiquitous understanding. If you are the King--you need people to understand the word King--and that you are the King. In pre-written civilization, mastering this means you rule your world. While the observable world is full of R/W/B--the means to recreate those colors are not. The unavailability is precisely why those colors were used for ceremonial and symbolic items. If you want to show that an idea is important--use the rare materials to create your message. The colors have been interpreted as different symbols in different places, but it is fairly uniform that 'special' status is given to those colors. I've linked below the wiki entries relating to the technology of reproducing those colors.
Red is commonly blood--literally life. The sight of blood in nature is fairly common... anywhere nature opens a vein. Early Reds in art were basically rust--more brown than red. Picture yourself using the early technology for creating true red. You are now crushing the husks of exactly the right insects to extract red dye. Scarcity.
White is commonly used as symbolic purity. Though the means to create white are not terribly rare, the simple trial and error of many cultures in history arriving at the same conclusion--white means pure--is pretty cool. And that is also a pretty clever result when we know that in 10,000 BC--no one knew that white is Achromatic. White is the 'empty' color in physics.
Blue is ubiquitous in our view because of the sky--it's 50% of what is visible on clear days--but again the means to reproduce it was scarce. Lapis lazuli, a blue stone, was one of the precious items of the ancient world. Replacing it with a technology was a technological marvel of that age.
tl;dr: Humans are social and competitive. Scarcity is an excellent driver of social status. Making colors is harder than we think--so some are special.
If I remember my college history of Law and Politics correctly, it goes as far back as the Roman Republic. Red White and Blue are the colours of independance, and symbolise a Republic.
Red, Yellow and Blue are the primary colors. Yellow doesn't show up that well on a White background, or with a Gold fringe, so may as well just use the two more bold ones...