Poverty, meanness, disappointment, produce contempt and dislike: But when these misfortunes are very great, or are represented to us in very strong colours, they excite compassion, and tenderness, and friendship. How is this contradiction to be accounted for? The poverty and meanness of another, in their common appearance, gives us uneasiness by a species of imperfect sympathy; and this uneasiness produces aversion or dislike, from the resemblance of sentiment. But when we enter more intimately into another's concerns, and wish for his happiness, as well as feel his misery, friendship or good-will arises from the similar tendency of the inclinations.
A bankrupt, at first, while the idea of his misfortunes is fresh and recent, and while comparison of his present unhappy situation with his former prosperity operates strongly upon us, meets with compassion and friendship. After these ideas are weakened or obliterated by time, he is in danger of compassion and contempt.
Hume, Dissertation on the Passions, Section III, 6 (3.11-12). Most of the Dissertation on Passions is a condensation of Book II of Hume's Treatise of Human Nature, but this is one of the passages that in DP that has no close parallel in THN. I find this passage somewhat obscure, but I take it that the point is that imperfect sympathy with the poor and unfortunate produces an aversion, because the uneasiness of such sympathy is on its own like dislike; but when our sympathy is extensive enough to encompass desire for the happiness of the people in question (when we enter into their desire for happiness as if it were something like our own) then the sympathy, while still having that uneasiness that is like aversion, has a tendency that is similar to that of benevolence and affection. To put it in different terms, the distinction here is much the same as that which is sometimes expressed by distinguishing compassion from pity, in the sense in which the latter involves a condescension, or focus on the pathetic or contemptible character of what is pitied. As Hume says, there is a compassion with contempt and a compassion with friendship. One can tip into the other depending on the degree and manner in which we 'put ourselves in their place', as we say.