The mechanism of tail regeneration is present in all reptiles, but only lizards use it, and not all of them.
For example, iguanas, chameleons, and monitor lizards do not have this ability. A detached tail distracts the predator, allowing the lizard to escape and hide.
“It is likely that a genetic mutation became established in lizards during evolution by chance,” says Svyatoslav Zabelin. “Perhaps they were often caught by their natural enemies by this part of their body.
With crocodiles, for example, it is too dangerous to do this — one could end up headless. A snake can also bite, and you can't catch a turtle's short tail — in danger, it simply retracts under its shell.”