Topstitching the inside AND outside seam of pants
Since this was mass-produced clothing, they probably do have a special machine for it! You can see an example in action around 2:45 in this video "How It's Made: Jeans". They're using a machine like this one, the Singer 261u:



You can see how the arm is shaped in a way that would allow you to scrunch up the leg.

You could try topstitching like this on a typical home sewing machine, but success would depend on the thickness of the fabric and how skinny the legs are... either way, take it slow!!

Alternatively, a common finish on pants is to only topstitch one set of seams. You can easily do this on a typical home sewing machine! For example if you want topstitching on the outside, sew and topstitch the outer seams before doing the inside seams. This way you have plenty of room to maneuver. Then you can complete the inside seams.

Another option is to topstitch the inside seams, and then partially topstitch the outside seams, usually just past the pocket - again, easy enough to do on a typical machine. You can see a tutorial for this sort of assembly here.