One example that comes to mind is terrific which originally denoted something quite terrorising while now it has positive connotations... How and why did these changes occur?
1660s, "frightening," [...]. Weakened sense of "very great, severe" (e.g. terrific headache) appeared 1809; colloquial sense of "excellent" began 1888.
So the transition was gradual in this case, unlike with many slang words that are used to mean the opposite thing on purpose.
The OED says this slang is now especially used for skateboarding and surfing, and the first quotation is from a 1983 UNC-CH Campus Slang by the University of North Carolina, Chapel Hill:
Sick, unbelievably good: The Fleetwood Mac concert was sick.
bad adj 1 good; tough. US, 1897.
sick adj ... 6 excellent; wonderful. On the principle that BAD means 'good' US.
Partridge notes bad is much older, and the OED gives the source as George Ade's story of a black shoeshine boy, Pink Marsh : a story of the streets and town (1897):
She sutny fix up a pohk chop 'at's bad to eat.
It says its originally US slang and means something good or excellent, especially stylish or attractive. The later quotations trace its use through black and jazz slang (1928, 1955, 1959, 1971 and 1989) until more 'mainstream' use is noted in a US newspaper in 1995 and a UK book in 2006.
The OED has another similar meaning of bad which is originally African-American and used of a person who is so dangerous they inspire admiration, or impressively tough, or especially formidably skilled. The earliest quotation is from 1843 but only meaning dangerous or hostile without admiration. Their next earliest is in 1938 in a musical context, as are some of the others, and I can see some overlap of these meanings.
A Dictionary of Slang and Unconventional English (2002) gives a possibly unrelated term using sick, but it's somewhat similar:
In knock (one) sick, to astound, 'flabbergast': coll.: - 1923 (Manchon).
Usually because some spin-doctor (a profession far older than the term) saw an opportunity. Terry Pratchett, Lords and Ladies (wherein elves are inhumanly cruel):
Elves are wonderful. They provoke wonder.
Elves are marvellous. They cause marvels.
Elves are fantastic. They create fantasies.
Elves are glamorous. They project glamour.
Elves are enchanting. They weave enchantments.
Elves are terrific. They beget terror.
The thing about words is that meanings can twist like a snake, and if you want to find a snake look for them behind words that have changed their meaning.
No one ever said elves are nice.