When building docs using pre-commit, the _build directory is included in the packaged output of sphinx, As a result the directories get more and more nested until sphinx finally encounters a runtime error. It also takes gradually longer for each build.
All that is required is adding _build to the list of excluded directories in the pre-commit.yaml file.