Flags are important in Treasure Island because they represent the distinction between the men loyal to Captain Smollett and Squire Trelawney and those who are pirates. The distinction in question is not just a matter of loyalty, however; it is at its heart a matter of philosophy and morals. The British flag, the Union Jack, represents law, order and civilization, whereas the Jolly Roger represents lawless freedom, a loose association always bordering on anarchy, and selfishness.
Those who live and fight under the Union Jack are unified not just by a common goal, but by a common belief system. They work together to achieve their goals, and in so doing try to adhere to the laws and tenets of British society. This is exemplified by an incident that occurs prior to the pirates attacking the stockade, when Captain Smollett chastises the rest of his party for succumbing to curiosity rather than keeping to their posts. He reminds them that they all have a responsibility toward each other and that this duty comes before their own desires. This reminder of their principles helps the outnumbered British party successfully defend the stockade. Further, the British follow the laws of their country when dealing with the pirates, even though Treasure Island is not part of Britain.
Conversely, those who rally around the Jolly Roger are only bound together by a loose democracy and selfish desire. Each of the pirates is motivated not by loyalty or duty, but rather by the desire to obtain a portion of the treasure for themselves. Further, by eschewing the Union Jack in favor of the Jolly Roger, the pirates have separated themselves from England and its laws. They embrace this freedom, but with such freedom comes a lawlessness that contributes to their downfall. Finally, while the Jolly Roger is a standard for the pirates, it is a standard that represents a dysfunctional democracy, where the worst, or most feared, among them bullies and cajoles his fellows to support him against others. It is an association that is dependent on the strength of its leader and that is always on the edge of anarchy.
It is this distinction between the British and the pirates, one of values and philosophy, that impels Captain Smollett to bring the Union Jack from the ship and raise it above the stockade on Treasure Island. He is making manifest the difference between his group and the pirates, who raise the Jolly Roger to show their capture of the ship. His group is unified under the laws and civilization of Britain; the pirates are only unified in their lawlessness and greed.