You’re assuming the bulk of ChatGPT’s coding knowledge comes from stack overflow. I suspect training directly on code bases and documentation is more important.
Anything involving genuine reasoning needs to be done by a human. It’s a great documentation parser. A step up in search engines. But a thinking machine it is not (yet).
I'm also not sure how "reasoning" at inference time is relevant here. You seem to be conflating unsupervised offline training with inference. The ironic thing is that the behavior you describe actually works, you can try it right now. Add code documentation to your context window and ChatGPT will happily write code using that documentation as reference.