I believe flags started out as a way for people to tell each other apart on the battlefield and they were based on coats of arms, like the Slovene said. They were needed because in Medieval armies, you'd have troops from 30 different duchies and baronies in a single army so you needed to be able to tell your friends apart from your enemies. So there's no need to search for deeper meanings behind the colors than what
>>4290413 said.
As for the tricolor design, apparently it originated from a flag the prince of Orange used in the eighty years' war and the Netherlands became an independant country under that flag. Guess that tale made an impression on revolutionaries and other riff raff so with the rise of nationalism designed tricolor flags for themselves. And the tricolor became associated with republics and shiet. Of course there are exceptions like the Russian Empire. But all accounts point to a strong Dutch influence in the origin of the Russian tricolor.