Just read an article about the expression and its origin: “As mad as a hatter”. The poor sould back then, they didn’t know any better.
It’s not about the Brexit, although sometimes you wonder what professions some of them have.
Being a Brit, I can answer this one. The Mad Hatter is a character in Alice in Wonderland by Lewis Carroll. But I believe that character cam as a result of hatters often going mad because they used mercury in their profession and that is not great for the brain.
It might be that Mad as a hatter - Wikipedia tells about all that can be known about the expression. Alice in Wonderland is full of things based on similar at the time well-known idioms (March Hare, little Bill, etc)
Of course, you also get the expression as mad as a March hare. If you live somewhere that has hares, as I do, I can attest they do indeed appear a bit mad in spring. A bit like puppies.