The term comes from the old days of wooden ships, when one ship would hang the flag of its enemy before attacking another ship in its own navy. Because the enemy’s flag, instead of the flag of the real country of the attacking ship, was hung, it was called a “false flag” attack. LINK