MCP23017 IO expander not properly pulling up signal
You might have a bad ground that is causing the MCP23017 to reset. Next time that happens again, check if the port registers were reset to their power on value meaning the whole port will be set as an input instead of output.