Also, to whom was it originally addressed? Assuming it was not initially started in drama.
The short and unsexy answer: we don’t know where it came from. But there’s a few ideas about the origins of this phrase, some pass the smell test, others certainly don’t.
HOWEVER, the basic takeaway is that the notion that wishing someone good luck is in fact bad luck exists widely outside of theater, so telling someone to go get rekt right before getting on stage makes some sense as a sort of long-term escalation of good-luck-is-bad-luck sentiments being tossed around. There’s non-ironic good luck rituals before theater though, in opera it’s customary to pretend to spit on someone (“toi toi toi”). The theater has a lot of luck rituals in general, it may just be that the success or failure of something done live and judged by a random assortment of is people dependant on so many different elements that it seems down to just luck. Other funny little rituals include no whistling backstage, not saying Macbeth, a perfect dress rehearsal foretells a bad opening night, and the “ghost light” being kept on so the theater is never dark. (Curiously, Tosca is the opera world’s equivalent of Macbeth, but there’s no taboo about saying the title.)
Anyway here’s some theories on “break a leg:”
The Methuen Drama Dictionary of the Theatre, 2013. There’s an entry for “Break a leg,” “toi toi toi!” as well as a larger one for “taboos and superstitions” which is good.
“Towards a Metaphorical Reading of 'Break a Leg': A Note on Folklore of the Stage” by Alan Dundes. Western Folklore, Vol. 53, No. 1 (Jan., 1994), pp. 85-89 http://www.jstor.org/stable/1499654 This article is what makes me lean to the Yiddish theory.
Despite the origin stories given by /u/caffarelli, the Oxford English Dictionary does not list an attestation for the modern idiomatic use of the phrase "break a leg" until 1921. Therefore, although the notion behind the phase is quite old, I don't think we can reasonably assume that the phrase was current before the late 19th or early 20th century.
In this light, the Yiddish-German origin story might hold some credibility. In the Anglophone world, late-19th century theater was full of German emigrants, Jewish or otherwise. This cultural influence was particularly strong in the United States. However, a cultural, rather than etymological explanation, may be correct, as the article that /u/caffarelli posted suggests.
Related curiosity: the spanish equivalent to 'Break a leg' is 'Mucha mierda!', which can be translated as 'Lots of shit!'. This desire of lots of shit is supposed to meant that if the premiere of your performance was a success, it meant a lot of people would go to the theater, so their horses would wait in the streets, shitting the entrance. Thus, a lot of shit would meant a huge success.