DOC/CI: Fixes to make validate_docstrings.py to not generate warnings or unwanted output
Follow up of #23514. Making `validate_docstrings.py` not generate warnings or other unwanted output, mainly when called with `--format=json`. This includes preventing matplotlib of opening windows with the plots, and also canceling output from flake8.

Also, fixed some bugs, and corrected some tests that weren't being run. 

The script should now be ready to be added to the CI (and to generate the json file with the docstrings state of the art).

- [X] tests added / passed
- [X] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

CC @TomAugspurger 