“Takes the cake”

Something “takes the cake” was originally something very good (as if winning a cake as a prize), but now is used mostly in the ironic sense of something very unusual or very bad. “Takes the cake” has been cited in print since at least 1877.
 
     
The Free Dictionary
something takes the cake
something is the most extreme example. I’ve known some jerks but you take the cake.
Usage notes: usually said about something bad
 
(Oxford English Dictionary)
to take the cake, (U.S. cakes): to carry off the honours, rank first; often used ironically or as an expression of surprise. Cf. BISCUIT 1d.
1847 W. T. PORTER Quarter Race Kentucky 120 They got up a horse and fifty dollars in money a side,..each one to start and ride his own horse,..the winning horse take the cakes.
1884 Lisbon (Dakota) Star 25 July, Sherriff Moore takes the cake for the first wheat-harvesting in Ransom county.
1886 Pall Mall G. 2 Sept. 5/1 As a purveyor of light literature..Mr. Norris takes the cake.
1900 T. DREISER Sister Carrie xxiii. 249 Pack up and pull out, eh? You take the cake.
1904 A. BENNETT Great Man xxv. 275 My bold buccaneer, you take the cake… There is something about you that is colossal, immense, and magnificent.
1938 G. HEYER Blunt Instr. ix. 158 I’ve met some kill-joys in my time, but you fairly take the cake.
 
Google Books
A Case for Divorce: as told by the maiden lady across the way
By James Otis
Chicago, IL: Dramatic Pub. Co.
1877
Pg. 36:
Tobias. [At end of dance.] Good! good just as slick as oil. That takes the cake, the oven, and the bakery, and the baker.
 
8 April 1877, New York (NY) Herald, pg. 1, col. 1 ad:
ALF.—GOT STUCK ON ANCE WOOD’S SINGING School and Irish opera; much better than theatre; It “takes the cake.”
U.G.
   
21 June 1878, The Evening Picayune (New Orleans, LA), pg. 2, col. 4:
But the wheel of fortune takes the cake.
 
20 August 1878, New Orleans (LA) Times, pg. 4:
The small boy in the pantry commits himself to slang when he takes the cake.