Early warships carried flags from many nations on board in order to elude or deceive their enemies. The rules of civilized warfare called for all ships to hoist their true national ensigns before firing a shot.
A warship that flew first one flag and then hoisted their own flag when they got within firing range — scant minutes before firing a shot — were said to be dishonourable. This behaviour also proved that they were untrustworthy as well and therefore not good allies to consider at any point in the future.
One’s true colours that shine through at the last minute are generally not good colours for the long term.