You have adware/malware installed. Use Malwarebytes Anti-Malware for Mac. It may be necessary to run more than one scan. After scanning a couple of times, restart the computer and test. If necessary, follow the manual instructions. Do not download any other programs that are listed in the articles.
See if the below helps. I would scroll down to the below or you might fall asleep.
Step 1. Eliminate Yahoo Redirect from Windows.
Step 2. Delete Yahoo Redirect from Mac OS
Step 3. Uninstall Yahoo Redirect from Internet Explorer
Step 4. Remove Yahoo Redirect from Microsoft Edge.
Step 5. Erase Yahoo Redirect from Mozilla Firefox.
Step 6. Get rid of Yahoo Redirect from Google Chrome.
Step 7. Eliminate Yahoo Redirect from Safari.
https://www.2-spyware.com/remove-yahoo-redirect-virus.html.
Safari/Preferences/General - see what the Home Page is set to. If something you don't recognize, see if you can replace it with something you want.
Safari menu/Clear History.
System Preferences and remove any Profiles you see.