Dysentery and chronic diarrhea were so prevalent during the American Civil War that there was an honor code among soldiers: you couldn’t shoot a man while he was defecating. – WTF Fun Facts
Source: https://www.thecut.com/2016/06/diarrhea-is-the-wartime-enemy-no-one-mentions.html
This has been a common code since the beginning of war
Checking the source, ‘Recollections of a Private Soldier in the Army of the Potomac’ By Frank Wilkeson, p. 121, it is actually about sharpshooters, there was nothing in that section related to dysentery.