Remember that meme started when theatres were very popular venues with huge crowds, which often used fire(!) to illuminate the live action on stage, and had no safe exits.
The phrase originally came from Schenck v. US[1], in which Justice Oliver Wendell Holmes, Jr. said:
The most stringent protection of free speech would not protect a man in falsely shouting fire in a theatre and causing a panic.
Few recall that Holmes used this argument to justify imprisoning a group of socialists for the crime of attempting to mail leaflets. These leaflets protested US involvement in The Great War and urged people to protest the draft.