It happens to me all the time. I used to use Gmail API to send mail (personal hobby app, to my own account). Every now and then Gmail would randomly refuse to authenticate through the API because of unsafe or suspicious access or some other BS. Then I would need to jump through some hoops (log in manually though browser, toggle on/off the "allow less secure app" setting, the disable unlock captcha setting, and it would work again for a while before acting up again.