The check_pydantic_models.py script patches all pydantic imports, including the imports from external modules. #17144 introduces a dependency to scim2-models that requires pydantic >= 2.7 and breaks the script.
After discussing it on #synapse-dev, it seems check_pydantic_models.py should ignore external modules.
Related to matrix-org/synapse#13502, matrix-org/synapse#16332