This might be fine if your iMac is a within a certain age but with a mid-2010 or 2011 iMac, running High Sierra 10.13.6 is as high as Apple will allow the OS to go.
I get exactly the same problem as reported above - all my Gmail accounts within the Mail app are suddenly non-operational because I changed the password as part of a security review (prompted by Google) and from this point I have been unable to receive mail to my Gmail account using the Mail app on my iMac. The password field does not appear on the Details screen within the Internet Accounts part of Systems Preferences - I get the following:
You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy for keeping apps secure.
You can let the app developer know that this app doesn't comply with one or more Google validation rules.
So I am letting the app developer know so that Mail can be updated to cope with it...and asking for this upgrade will be available to users of Mail on High Sierra. Currently I am running Mail v 11.5 (2018).
The only workaround I can use on the iMac at the moment is webmail.