
There are different stories to explain the origin of this expression. At first, it looks like a contradiction but read below and you will understand why.
"The term “break a leg” was used originally, many say, to discourage evil spirits from deliberately causing one’s performance to suffer. According to this theory, wishing someone “good luck” would be invoking the “evil eye”. So “good luck” would actually cause bad luck for the actor. Thus, “break a leg”, by this logic, would be a wish for good luck.
...
Another of the early documented references of “break a leg”, this time directly referring to theater, was in the 1939 A Peculiar Treasure by Edna Ferber, where she implies a different motive, “…and all the understudies sitting in the back row politely wishing the various principals would break a leg”. Thus, they say it hoping the principal actors will break their leg so the understudies can possibly take the lead.
Another possible construction is the German phrase “Hans un beinbruch”. The sentiment here is “Happy landings” in English. Both English and German pilots use the term, but the literal translation is “breaking all one’s bones”. It is possible actors adopted this phrase, as it was just after WWI that the “break a leg” sentiment seems to have gained widespread popularity.
The term “break a leg” may be traced back to the Elizabethan language. To “break a leg”, in Shakespeare’s time, meant, literally, to bow- by bending at the knee. Since a successful actor would “break a leg” onstage and receive applause, the phrase would, in effect, be a wish for good luck. ...
Others trace “break a leg” to the tradition of audiences in Ancient Greece. Instead of applauding actors, audiences would stomp their feet. Stomping to the point of actually breaking a leg is unlikely- but still, the phrase may be figurative and not literal.
All this information has been taken from Today I Find Out, a website with curious, interesting and funny stories.