Anyone who's been in a spelling bee could tell you how closely "deserts" in the expression "just deserts" and "desserts" sound alike. And they should!
After all, they both come from the same root verb in French, desservir, to merit by service (deserve) and also to serve well, as in clearing the table.
At one time the entire dinner cloth was removed before the final sweet or dessert was served. Changing the cloth was how dessert got its name.
The Old French "deserts," as in a deserved reward or punishment, is pretty much obsolete today except when used in the cliché "to receive one's just deserts."
The expression was first recorded in Geoffrey Chaucer's work circa 1380. These "deserts" may be sweet, but, then again, they may not be.
SOURCES: 'The Encyclopedia of Word and Phrase Origins,' by Robert Hendrickson; 'Morris Dictionary of Word and Phrase Origins,' by W. and M. Morris; 'The Barnhart Dictionary of Etymology,' by Robert K. Barnhart; 'Dictionary of Word Origins' by Jordan Almond; Larousse Modern Dictionary; 'The Story Behind the Words,' by Morton Freeman; 'Have a Nice Day,' by Christine Ammer.