The most obvious answer might be a reference to those who counted the beads (or beans) on an abacus. However this is not borne out by an internet search.
According to the August 11, 2000 issue of the Word detective:
"Bean counter" has an interesting history. It seems to have first appeared in the mid-1970s in the U.S., and its original use was simply as a vivid synonym for "accountant," especially one who brooked no nonsense. Its first known occurrence in print was in a 1975 Forbes magazine article that referred to "a smart, tightfisted and austere 'bean counter' accountant from rural Kentucky," though we can assume the quotation marks meant the writer had heard the term in use before the date of the article. In any case, the allusion is clearly to an accountant so dedicated to detail that he or she counts everything, down to the last small, but still important, bean.The 'wiseGEEK' site has a more graphic analysis that includes:
By the 1980s, however, most appearances of "bean counter" in the media were taking on a derogatory tone, and "bean counter" is now frequently used to mean a nitpicker who, lost in the numbers, fails to see the "big picture."
While an accountant might be asked to perform a thorough inventory of his or her company's assets, only a bean counter would literally count the number of beans contained in the company kitchen's pantry. A financial bean counter may also scrutinize each department's budget to find any form of potential waste, no matter how insignificant or nominal it appears to be.
It is possible that the description was inspired by overzealous kitchen inventory takers who insisted on counting every bean in a bag or every potato in a sack. The act of counting every bean to the exclusion of more important duties would be viewed by many as the ultimate act of micromanagement. Perhaps the term "bean counter" entered the popular vernacular through the commercial or military food industries, where strict inventory controls are common.