Cakewalk ceremonies were held on slave plantations. The dancers were slaves, who used the opportunity to mock the mannerisms of the aristocratic Southern fuckers who owned them. They'd wear flamboyant costumes and exaggerate the typical dancing moves of Southern gentlefolk, their master and his slavery-loving friends in particular.
Library of Congress
"Whiteface" remains controversial to this day.
Theoretically, that might have been a pretty decent way for the slaves to vent some steam over their unfortunate situation. However, the cakewalk came with a catch: The person doing the judging was the slaves' master. So instead of the slaves having some fun behind their owner's back, cakewalks were basically a sadistic game of sanctioned mockery that carried the risk of turning into Joe Pesci's "I'm funny how?" scene from Goodfellas at any given moment. A cakewalk was essentially a roast, except the person being roasted could have anyone on the dais flogged for the rest of their lives whenever he wanted.
Or literally roasted.
When America came to its senses and reluctantly gave up the slavery thing, the dance endured and slowly started evolving. It became a staple of minstrel shows where it went full throttle racist; instead of showing the slaves as mocking whites, the performance now portrayed them as desperately trying (and ultimately failing) to emulate civilized white culture.
Pictured: Civilized white culture