I think, maybe this is RMW issue somehow?
not at all likely , which pin is having its expected digitally "read back" value changed by a digital write to another pin on the the same port ?

as ioannis suggests this is looks very much an EMI problem that could most likely could be ameliorated by having the switch circuitry of more suitable impedance and using appropriate adc conversion speed along with sample hold time and rate.


with no schematic or code to look at it might just be bad code who would know