It's an expression believed firstly used in theatre, typically said to actors or musicians before they go on stage, means "good luck"...come to common use in nowadays.
Amongst all sorts of it's origins, one version says it might related to superstition.
Back in those days, actors believed that there're bad goblins/spirits can hear their wishes, and then give the "bad luck"(the opposite of what you said) to whom you said "good luck" to.
So people in theatre believed that to say "break a leg" will lead to "good luck" ...
hope you have fun in learning ... :)