When Homebrew starts acting odd on my Mac, I’d run one command before I go searching any forum: brew doctor. It looks over your system for things that commonly break Homebrew and tells you what it found.
The basic version needs no options:
brew doctor
If all is well, it says your system is ready to brew. If not, you get a list of warnings, usually with a hint about what to do. The manual also says it exits with a non-zero status when it finds a potential problem, so you can use it in a setup script:
brew doctor || echo "Homebrew wants attention"
Curious what it actually checks? brew doctor --list-checks prints the names of all the checks. You can pass one or more of those names as arguments to run only those checks, which is handy when you have fixed one warning and want to confirm it is gone without reading the whole report again.
The caveat is in the manual itself, and I like how honest it is: the warnings are mainly there to help the Homebrew maintainers debug when you file an issue. If everything you use Homebrew for works fine, they ask you not to worry and not to file an issue. So read the output as a list of suspects, not as a list of things you must fix. A warning about something you did on purpose can stay.
Further reading: Homebrew manpage