Apparently:
"The phrase meaning to be on the run from something dates to the turn of the 20th century. It probably comes from the English dialectical verb lam meaning to beat or to strike. To take it on the lam was to be beaten, which was usually followed by running away. Lam may ultimately be of Scandinavian origin, but that isn't definitively known."