They're deceptively simple. If you want to get into the history of modern manufacturing, a lot can be written about the development of gauges of accurately known dimensions.
Go find a PDF of "Fundamentals of Mechanical Accuracy" by Wayne R. Moore, if you haven't already seen it. That book, along with George Daniels text "Watchmaking" are some of the top inspiring works on the mechanical arts in my collection.
Somewhat sadly a lot of the drive for that tolerance was weapons, until we could accurately make very high tolerance (for the day) parts you couldn't use parts from one rifle on another without a smith, it certainly wasn't field serviceable - this imposed a lot of maintenance overhead until they solved it properly.
It seems like we really like to push the limits when it comes to shooting each other.
That the tolerances are so precise is exactly why you can do that on most modern rifles. It depends on the design - specifically, how they achieve headspace. On an AR-15, or almost any firearm with a similar bolt locking arrangement, bolts - indeed, entire BCGs - are swappable in practice, and people do that routinely without bothering with gauges regardless of what the manual says. On AK and similar designs, yeah, that's a really bad idea.