This is Euclid's Elements Book XI Proposition 9. "(Straight-lines) parallel to the same straight-line, and which are not in the same plane as it, are also parallel to one another."
Pick any point on $m$, and in the two planes $lm$ and $mn$, drop perpendiculars from it onto the lines $l$ and $n$. The point/perpendiculars define a plane to which $m$ is perpendicular (by Proposition 4). And by Proposition 8, if two straight lines are parallel and one is perpendicular to the plane, then so is the other. Hence $l$ and $n$ are perpendicular to the same plane. Finally, Proposition 6 says that if two straight lines ($l$, $n$) are perpendicular to the same plane, then they are parallel.
Reproducing the proofs of Propositions 4, 6, and 8, and everything needed to support them would require a very lengthy answer, and Euclid is a standard work and widely available, so I hope I'll be forgiven for not making this answer self-contained.