I've heard some people (non-historians) say that the members of the societies that eventually made slavery illegal started caring more about human rights during those centuries. If so, why did that happen?
Disclaimer: This is not meant to be a rhetorical question in favor of slavery. Also, I understand that while slavery is illegal in many places, it (and similar practices) is still done and is still an issue today.
This is debatable, according to historians, but I think you are probably missing a major facet of the change--Economics. Sure, people started to realized that all men should have a right to freedom, but think about when these changes started happening. You mention the 19th and 20th centuries. These centuries are also known as the Industrial Revolution, and they can give some economic reasons for some of the support to the abolitionist causes. I'll pick just one country to give you examples, and I think I'll go with Britain.
At the beginning of the Industrial Revolution in England, slavery was a booming rade that fed the economic growth. The British Library and the BBC actually have some short, good resources on that here and here. Slavery fed the Industrial Revolution by feeding its profits and investments into the British economy. It was a sustainable market form at that time, but the farther we get into the Industrial Revolution, the less sustainable the market gets. Slaves are expensive to purchase and expensive to maintain--you might not have to pay them a wage, but you do have to provide for their room, board, and health. Towards the date of abolition, it was almost cheaper to provide a freeman a wage, and let him pay all his own expenses. THose freemen were also extremely jealous of their jobs, and got very angry if it appeared that some lesser foreigner was taking their work. Near 1807, we can start to see few economic reasons for the support in Seymour Drescher's Econocide: British Slavery in the Era of Abolition, especially the chapter "Economic Conjecture and Abolition Bills, 1797-1806." Drescher makes to assertions on this point: First, he states that the support was a laissez-faire reaction to the signals in the economy; and Second, that "abolitionist victories are supposedly a form of economic warfare against presumed rivals." Econicide actually has some wonderfully detailed information on slavery, abolition, and the British economy.
Here are some other resources about abolition and economics:
Roger T Anstey's "Capitalism and Slavery: a Critique"
DB Davis's The Problem of Slavery in the Age of Revolution, 1770-1823
David Eltis' Economic Growth and the Ending of the Transatlantic Slave trade
Seymour Descher's Capitalism and Antislavery: British Mobilization in Comparative Perspective
Eric Williams' Capitalism and Slavery
There's another great set of resources in some questions previously asked in this sub:
Historical Debates on Economics and Slavery
TL;DR: It's possible that the Industrial Revolution made the economic model for slavery unsustainable.