Lizards, like us, are chordates. One of the defining characteristics that all chordates share at some point in their development is the presence of a notochord: a stiff rod of tissue that runs along the dorsal side of the animal, just beneath the hollow dorsal nerve cord. (Yes, hollow. This is the result of its origins in the neural tube that forms early in chordates' embryonic development.) In most vertebrates the notochord's replaced by the spinal column. Another chordate feature is the presence of pharyngeal pouches (homologous to gills in fish, and to structures in the jaw and inner ear in mammals), and there's also the tail. A tail that extends beyond the anus. And it's that last fact that sets lizards & scorpions apart, when it comes to losing their tails.
This ability to shed the tail is known as autotomy, and it seems to have evolved in response to predator pressure: the tail may even continue to wriggle for a while, which would help to distract a carnivore long enough for the lizard to escape and to live another day.
And that longer-term survival post-autotomy has much to do with the fact that a chordate's tail is 'post-anal'. For when a lizard (eg a gecko, or a skink) loses its tail, the animal's gut remains intact; it can continue to take food in at one end & pass faeces out the other.
Scorpions are arachnids, related to spiders and mites. As a paper published earlier this year in PLoS ONE notes (Mattoni et al, 2015), scientists have known about autotomy in arachnids, but up until now they'd only observed the voluntary loss of legs. However, Mattoni & his co-workers augmented data from the field, and from museum specimens, with some (very careful!) experiments on live animals to demonstrate that at least some species of scorpions are able to detatch their tails.
As for lizards, a tail (more correctly, a 'metasoma') continues to wriggle for a while after it's detatched, and may also act as a distractor to allow the animal to escape a predator. There is, however, a drawback - with its tail the scorpion also loses its anus and the penultimate portion of its digestive tract. And neither metasoma nor gut regenerates.
On the face of it, you have to wonder why caudal autotomy (the ability to voluntarily shed the tail) would ever have been selected for in scorpions. They're unable to sting ever again, which would leave them with a much-reduced ability to defend themselves or to kill large prey items. And once the open end of the intestine is closed by scar tissue - which takes about 5 days - they can no longer pass faeces from the gut, which must put a dampener on their ability to take food in at the other end - a case of enforced constipation? (The authors note that in at least some cases, the pressure of accumulating poo may trigger another autotomic event, when the animal loses the segment at the 'new' end of the tail.)
However, for the scorpions, all was not lost. The researchers' lab experiments showed that the tail-less arachnids still managed to survive for up to 8 months post-amputation, occasionally eating small prey items. Which would be irrelevant if they were unable to pass their genes on - but the animals were also able to reproduce. In mating experiments, tail-less males were nonetheless able to court and mate with females on multiple occasions. This means that tail-shedding may still provide a selective advantage, in that it allows animals to escape predation and go on to reproduce.
You should also read Ed Yong's take on how the scorpion lost its tail :)
C.I.Mattoni, S.Garcia-Hernandez, R.Botero-Trujillo, J.A.Ochoa, A.A.Ojanguren-Affilastro, R.Pinto-da-Rocha,& L.Prendini (2015) Scorpion sheds 'tail' to escape: consequences and implications of autotomy in scorpions (Buthidae: Ananteris) PLoS ONE. doi: 10.1371/journal.pone.0116639