Here is the code: https://github.com/ampproject/amphtml/tree/main/validator
All of the rules are written in human-readable config language. Here are the rules for common HTML elements (https://github.com/ampproject/amphtml/blob/main/validator/va...) and there are rules per-amp-tag (example: https://github.com/ampproject/amphtml/blob/main/extensions/a...)
You can build it, run it locally, etc. There are open-source implementations that run in the browser, in a vscode plugin, on the command line via NPM, etc. Other entities can and do use the same code for their validation of AMP. Pull Requests are accepted from anyone and those changes land in Google production and all of the aforementioned tooling targets within a few days. There is documentation on how to contribute to and edit these files (https://github.com/ampproject/amphtml/blob/main/docs/compone...).