In taxonomy (the branch of science that classifies living things into groups), single attributes rarely define a genus or species. In addition to being legless, snakes are defined by their lack of eyelids, big scales on their bellies, single lung, etc etc. Legless lizards have eyelids, small belly scales, two lungs, a non-forked tongue, etc etc. In addition, many legless snakes have small vestigial feet.
Snakes are understood to be all descended from a common snake ancestor, so should have multiple features in common
from the [legless lizard Wikipedia page](https://en.m.wikipedia.org/wiki/Legless_lizard)
>These lizards are often distinguishable from [snakes](https://en.m.wikipedia.org/wiki/Snakes) on the basis of one or more of the following characteristics: possessing eyelids, possessing external ear openings, lack of broad belly scales, notched rather than forked tongue, having two more-or-less-equal [lungs](https://en.m.wikipedia.org/wiki/Lung), and/or having a very long tail (while snakes have a long body and short tail).
The answer lies in the ancestry of any species.
On detailed examination of the legless lizard, the scientists realized that it had more in common with lizards than snakes. For eg, the legless lizard has ears and remnants of their limbs and eyelids, snakes have none of that.
Now the criteria has been created in such a way that all the recognized species of plants and animals are grouped according to their common characteristics, so if 2 organisms have more in common, they are more likely to grouped “closer”, if they have less in common, then they will grouped apart.
All organisms follow this division based on having/not having common characteristics:
Kingdom > division/phylum > class > order > family > genus > species
So for example cat and dog, they both belong to the same groups down to the level of order (Animalia > chordata > mammalia > carnivora) but after that their families are different and at that level the stuff they have in common is not enough to put them in the same group so they are grouped in different families according to the criteria.
Hope this helps, feel free to ask more questions:)
Edit : switched chordata and mammalia because chordata is a phylum and mammalia is a class and I am an idiot
Think of it like comparing bats and birds. Both fly and have some overall similar characteristics, but both are clearly anatomically different, and evolved from totally different lineages.
Same with snakes and legless lizards. Their skulls and much of their physiology is quite different. They are more related to each other than bats and birds, because they’re both reptiles, but really they have a lot of differences.
One interesting tid bit is that the skin/body of snakes can stretch, to swallow large prey. Most reptiles, and lizards specifically, can not stretch their skin, and so legless lizards only eat small prey, like bugs. They cannot stretch their body to swallow something like a mouse, and their mouth cannot unhinge itself like a snake to fit something that big into their mouth either.
Latest Answers