distutils was officially deprecated in python-3.10 and has been removed with the release of python-3.12. So currently the user_guide cannot be built with python-3.12 sphinx. This change just fixes flags.py not to use distutils.version but instead the modern packaging.version replacement module.
See https://peps.python.org/pep-0632/#migration-advice for more background
I have tested and applied this patch to ghc-9.6.2 on current Fedora Rawhide (which includes python-3.12) and also tried it on Centos Stream 9 which has python 3.9.