They had no knowledge of microbiology in ancient times, when the food laws arose. ANY animal has to be inspected (irrespective of keeping kosher, or halal) for signs of illness. Also, besides the low rate of TB in pigs (.4%) there's no transmission to humans from pigs. * It's a good guess that prehistoric hunting skills improved in order to nick the healthiest member of the herd of whatever game was being hunted.
Here is a paper on pig Mycobacterium.
Although not a problem in the US currently, was much more common, and still shows up in less stringent inspected meat locales.
https://vetmed.iastate.edu/vdpam/FSVD/swine/index-diseases/tuberculosis.
There is a bunch more info if you are interested.
Here is a short paper on kosher preps, check out the "kosher inspection"
https://www.growandbehold.com/blog/making-kosher-meat/