The story you remember is probably...The Happiness Patrol (1988). The question is Why?
Trapped in the Kandy Kitchen, the Doctor encounters the evil Kandyman, who makes sweets that kill.
The Kandyman was killed by his own fondant.
Find out more in the The Happiness Patrol episode guide.