We'll keep it short and sweet — this phrase has nothing to do with sugary treats.

It's easy to confuse deserts with desserts because both words are pronounced the same way. But the word deserts in this phrase has nothing to do with cake and ice cream, or with dry, sandy places. Instead, desert comes from the same root as deserve, which should help you understand the meaning of this phrase: a punishment that is justly deserved. Getting your just deserts refers to receiving an appropriate punishment for whatever offense you have committed.

As these examples show, just deserts is almost exclusively used to refer to punishment rather than reward:

Sometimes beloved characters depart much too soon, and sometimes villains get their just deserts. (New York Times) 

The man got his just deserts, but he didn't deserve to be tarred as a traitor without a trial and conviction (Washington Times)

Because dessert usually comes at the end of a meal, and is often seen as a reward for good behavior, it's easy to see how people often get this one wrong. In the following examples, desserts has been erroneously swapped in for deserts — but since these sentences refer to crime and punishment, references to sweet treats don't really make sense:

"Justice exists when people receive their just desserts. Committing a crime should have consequences. This was not justice," he said. (Washington Times)

In the United States, the consequences for breaking those laws are based on a system of retributive justice, where a person is held accountable for his crime and is meted out punishment in the form of his "just desserts." (Slate)

Remember, the word deserve is the key to understanding this expression: this use of desert is an old noun form of deserve. When you get your just deserts, you get the punishment you deserve — not a double chocolate brownie or a slice of pie à la mode!