I wish I could answer, but as far as I can tell, there is no simple mathematical formula for determining the sample size. (That is one of the reasons I would scrap the whole system and start from scratch.)
From a purely mathematical perspective, the lot size has very little to do with the sample size. Whether your lot is 1000 or 1,000,000, a sample of 100 pieces will give the same confidence.
It seems that the tables are based partly on math, and partly on perceived risk. For instance, accepting a bad lot of 1,000,000 carries a greater financial risk that accepting a bad lot of 1,000. So the tables call for a bigger sample to decrease the risk of accepting a bad lot.