Scraping Google using =IMPORTFROMGOOGLE() is based on publicly available information. The function accesses data that is openly accessible on the internet. And generally, accessing and scraping publicly available data from websites is considered legal.
Moreover, with IMPORTFROMGOOGLE, the scraping is made using multiple premium proxies and external rotating IP addresses, so you do not have to worry about the possibility to be banned from scraping Google Search results.
Nonetheless, it remains important to stay informed about the terms and conditions set by Google and exercise scraping responsibly and ethically.