Where did it come from? UNIX? Surprisingly, no: it descended from an older meme called Honeywell Brain Damage used to insult Honeywell's retarded Multics updates. It grew popular enough that Multicians.org dedicated an entire webpage to the meme (https://multicians.org/hbd.html). To quote them,
Sometime in the mid 1970s, Honeywell introduced iox_, a new input/output
API (although we didn't use the term API) for Multics. It was, to say the
least, not universally popular. At one point, Seth Steinberg installed a small
cardboard coinbox in the MIT SIPB office, with a sign on it to the effect:
"Help stamp out Honeywell Brain Damage (HBD). Get rid of iox_"
The box collected a very small amount of small change, less than $1.00,
mostly in pennies.
A few weeks, a clipping from Tech Talk, the MIT administration newspaper,
was added, showing some brain research going on at MIT, with the notation,
"Your pennies at work"
Eventually it made its way into Guy Steele's famous jargon file:
brain-damaged /adj./ 1. [generalization of `Honeywell Brain Damage' (HBD),
a theoretical disease invented to explain certain utter cretinisms in Honeywell
Multics] /adj./ Obviously wrong; cretinous; demented. There is an implication
that the person responsible must have suffered brain damage, because he
should have known better. Calling something brain-damaged is really bad; it
also implies it is unusable, and that its failure to work is due to poor design
rather than some accident.