In the 16th and 17th Centuries, the process of manufacturing and repairing hats
by hand involved the use of liquid concoctions containing substantial quantities
of lead and mercury, with the result that "hatters" ... the people who worked at the
trade of hats ... routinely became mentally incompetent and hallucinatory after
breathing all that stuff on their jobs for decades.
"Mad as a hatter" means that you/he and/or your/his ideas are as unreasonable,
irrational, unpredictable, undependable, ludicrous etc. as if you/he had been
hand-making hats for a living.
Pretty scary stuff. But that's what it was like for the common people trying to earn
a living in the cities a few Centuries ago.