First, let me make some general remarks not limited to Michel Foucault specifically. There is a balancing act in philosophy. On the one hand, it is not mathematics or hard science with clear standards of evidence and methodology, and there is vast ambiguity in most philosophically non-trivial notions and issues. To a lesser extent than poets, but philosophers are generally granted "poetic license". It covers high tolerance for the "sampling bias", to guess at patterns that are currently beyond reliable detection, speculation beyond what evidence might conceivably support, and subjectivity of approach. Philosophy could not play its well-known historical role as an incubator of sciences and generator of scientific hypotheses without such frivolities, and that is just one of its many roles. One person's bias is another person's interpretation. Just think about ancient atomists who certainly had to interpret and speculate a lot to motivate their theories, which nonetheless proved to be fruitful later.
This being said, there is a line beyond which philosophical frivolity collapses into junk science. Actually, let me correct that, there is no such line, there is only a wide blurry strip separating one from the other. Without trying to defend Foucault's "historical psychiatry" I'll point out that modern cognitive science is far from a firm consensus on mental disorders, especially in historical perspective, and was further from it at the time of History of Madness (1961) renamed into Madness and Civilization in 1964. Even Merquior, whose factual criticisms you are alluding to, admits that the point of the book is not historical accuracy but understanding modernity through its history, and "a call for the liberation of the Dionysian id", i.e. a form of
Foucault is considered a leading light of modern continental philosophy, and his writings apparently speak to sensibilities and concerns of many people, regardless of the impurities of his arriving at or presenting his ideas about human condition and human nature. In other works he gives interesting historical analysis and critique of Cartesian and Kantian ideas that shaped modern intellectual scene, see SEP entry for a brief review. "Dionysian id" brings up the memory of another who too so speaks, even as his descriptions of history of art and morals, or views about physics for that matter, would elicit a smile today. But even Carnap, a logical positivist representing an extreme of philosophy, where its non-empirical statements were viewed as pseudo-statements, and who called metaphysicians "musicians without musical ability", in a paper titled Elimination of Metaphysics, still grudgingly found a place for him there:
"The (pseudo) statements of metaphysics do not serve for the description of states of affairs, neither existing ones (in that case they would be
true statements) nor nonexisting ones (in that case they would be
at least false statements). They serve for the expression of the general
attitude of a person towards life... Our conjecture that metaphysics is a substitute, albeit an inadequate one, for art, seems to be further confirmed by... the metaphysician who perhaps had artistic talent to the highest degree, viz. Nietzsche... In the work, however, in which he expresses most strongly that which others express through metaphysics or ethics, in Thus Spake Zarathrtstra, he does not choose the misleading theoretical form, but openly the
form of art, of poetry."