Where does works a treat come from; is it related to sweets? I cannot find any reference to its origin, are there words omitted such as works [like] a treat?
It probably derives from the slang meaning of a treat as used in the following examples:
a treat, also treato - [late 19C+] wonderfully, extremely, excessively, e.g. that’ll go down a treat.
In phrases do one a treat (v.) [late 19C+] to suit one absolutely.
(Green Dictionary of Slang)
The extension of the meaning of treat to something that gives pleasures dates back to the 18th century:
- extention Sense of "a treating with food and drink, an entertainment given as a compliment or expression of regard" (1650s) was extended by 1770 to "anything that affords much pleasure."
According to a related question/answer, it seems to be a variant usage; both works a treat and works like a treat are used, though (primarily in British usage) the former is far more common (by about two orders of magnitude).
Treat is defined by Merriam-Webster as "an especially unexpected source of joy, delight, or amusement". So while a sweet would work as a treat, it is an example of a treat, but not itself the core meaning. If something works [like] a treat, it works very well, to the delight of the person who set this up.
A quick glance at websites reveals a common use in article headlines which report about some new investment or building project, change in behaviour or similar. It is usually used to positively evaluate the effectiveness of a remedy, behaviour, or project.