The Cake Walk originated some time around the middle of the 19th Century with the African American community. It appears to have started as a lampoon of the affected manners of the white upper classes. The men frequently wore top hats and carried canes, while the women had parasols. It followed the general pattern of a Grand March, a regular feature of the 19th Century ballroom, with the dancers promenading around the room in a column of couples, but then after the promenade, they would line up to watch any couple who wished, do their personal, often extremely silly, routine. Traditionally, the couple with the best routine would win a cake, though, while the name persisted, the baked goods did not.
The white folks either didn't realize they were being mocked, or they felt like they were in on the joke, and by the 1890s, it was popular on the Vaudeville stage and in fashionable ballrooms, arriving about the same time as that other new and exciting African-American invention, Ragtime.
The Cakewalk declined in popularity after the turn of the 20th Century, but it set a mindset for popular dances that persisted. After the Cakewalk, young and sometimes not-so-young dancers were willing to set aside decorum and be wild and silly on the dancefloor, to the horror of the more traditionally minded.
Here's a some original film of Cakewalks.