The first time the red flag was used politically was in His Britannic Majesty's fleet in the 18th Century. The sailors struck for better conditions, threw a few of the more repressive officers overboard and raised the red flag to show their defiance. They won the strike and the King capitulated, but later they went back on their word about no reprisals and many of the "ringleaders" were hanged.

But the red flag even predates this, in the Carribean in the 17th century there was a serious traffic in gold and many many pirates. Amongst the most vicious were the all-female pirate ships.
When they went to raid a ship they would fly their battle flag. Everybody has heard of the "Jolly Roger" skull-and-crossbones style pirate flag, but actually their flag was blood-red and Jolly Roger is a derivation of the French "Jolie Rougier", for these pirates were Red and Beautiful!