A code is an indicator. That's it. When the computer sees a sensor (input) or a controlled item (output) outside what is set for it's normal parameters, it sets a code for the related item. When you read the diagnostic chart (very few bother) it lists what systems the chart is supposed to diagnose.
When a lean or rich O2 sensor code sets, it's generally because the exhaust is rich or lean. And the O2 sensors are seeing that. But, Autozone will sell people O2 sensors because neither them nor the customer understand trouble code diagnostics. I saw them sell a guy 4 O2 sensors when the only problem was a blown O2 heater fuse. Stupid.
Trouble code diagnostics ain't rocket science. It does take a clear understanding of what happened and why though.