He probably caught it sometime after "City on the Edge." After all, he discovered it after running the standard crew physicals in "For the World is Hollow etc.", so he must not have had it the previous time he had a physical (a year before? Six months?). Therefore, in the timeline where he was stuck back in 1930s Earth from "City" onward, he wouldn't have gone to whatever planet McCoy Prime got infected on.