Amazing or unusual event or situation. There are some children’s games where the winner gets a cake, so to take the cake is to have dominated. Typically, refers to a surprising situation. (Compare to Beyond belief.)
“When she decided to wear a dress made out of sea kelp, I told her that takes the cake!