Despite its seemingly obvious metaphor, this has not proved to be an easy idiom to track down.
It is assumed to have come about through the literal idea of legs or feet supporting a body, holding it up, and it may have originally been a positive expression, conveying the notion of a lot of support, a firm grounding.
It may have come into Middle English from Old Norse, where it was indeed used in a positive manner. We can find it in the epic poem Egil’s Saga, dated to around 1220:
Stóð þá á mörgum fótum fjárafli Skalla-Gríms.
(Thus Skallagrim’s wealth had many legs to stand on) Egil-Skallagrim Ch. 29
The similarity between some of the English and Norse vocabulary may even have helped the expression to become absorbed more quickly into popular English speech – Old English stód (stood) is very much like the Norse stóð you see above, the verb “stand” was standa in Norse, standan in Old and Middle English. Our modern English word “leg” is related to Old Norse leggr, and “foot” in Old Norse was fótr.
Gradually, the expression came to be preferred in the negative, although it is sometimes used humorously today in the positive.
Naturally, the image of metaphorical standing is hardly restricted to English. Welsh uses exactly the same expression as in English, with dim coes i sefyll arni – it has no leg to stand.
Changing only the “leg” image, in modern Greek, you might say that an argument or idea doesn’t stand up: το επιχείρημα δε στέκει (to epiheirima de steki).
In Spanish, however, the expression is (something) no tiene de dónde agarrarse, which literally means “it has nothing to hold on to”.
Russian has a rather nice expression: ему́ не́чем крыть (jemú néčem krytʹ), which means “he has no good card to cover”.