Yes it means both, which can obviously be confusing, though there's a sensible enough history to it.
First cake was used as a metonym for all good things.
Dost thou thinke because thou art virtuous, there shall be no more Cakes and Ale?*
Shakespeare could have picked pies or cuts of meat or other things that on average go better with most ales than cake†, but he chose cake because cake is a good example of a generally good thing.
Then from that it became a figurative prize, and why not since it could well be a real prize sometimes too.
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. — W. T. Porter, Quarter Race Kentucky, 1847.
Now, consider that we can use the idea of winning a prize in a negative through sarcastic use:
I've met some idiots in my time, but you really win the prize.
And so, "take the cake" moved from only meaning something was very good, to meaning something was very good or sarcastically, very bad:
I've met some kill-joys in my time, but you fairly take the cake. — G. Heyer, Blunt Instrument, 1938.
"Take the biscuit" is simply an alternative expression for the same idea, in either way.
Whether positiver or negative is normally clear from context, and both would be commonly used.
*If anyone is wondering whether a particular minority religion took their use of that expression from this line, the answer is yes.
†Though some ales do go well with some cakes. There's as much to matching beers well as there is to matching wines, but it's a very underestimated skill.