It's a very interesting history lesson from the Marginal Revolution University (the online University I wrote about last September, led by Tyler Cowen and Alex Tabarrok). The video goes all the way back to the 19th century philosopher and historian Thomas Carlyle who coined the derogatory phrase. And the reason was his disagreement with economists (like John Stuart Mill) on the question of slavery and Black Emancipation. Carlyle's political philosophy was Hero worship (superiority of dictators like Oliver Cromwell or Napoleon) expressing the benefits of hierarchy where everyone should "know their place". He strongly opposed abolishing slavery for which he though was necessary to prevent order and force people to work who otherwise wouldn't do so. His ideas are said to have influenced both the rise of socialism and fascism in the 20th century (thus reinforcing Hayek's points of how these two ideologies are essentially the same as they compete for the same type of mind, in particular “those who have no strong convictions of their own but are prepared to accept a ready-made system of values only if it drummed into their ears sufficiently loudly and frequently", Hayek, 1944, pp. 143). Naturally the classical liberal economists of the 19th century opposed such backwards ideas. After all classical economists have witnessed and understood the benefits of the industrial revolution, something that was obviously not evident to philosophers like Carlyle.
Basically, the dismal science got its name because economists opposed slavery and supported liberty and equality. Hurrah for the economists!
HT: Cafe Hayek