How to Clean Safari when its homepage gets hijacked
Check for malware
Run a malware checker, such as Malwarebytes or Sqwarq’s DetectX, to ensure your Mac isn’t infected by true malware. If it is, you must remove that infection. Follow the checker’s instructions until your Mac is clean.
Once confident your Mac isn’t harboring malware, check the two Internet Plug-Ins folders in the main library (/Library) and your Home folder (~/Library). Move anything suspicious to a holding folder — in Documents, say.
In Safari’s preferences, reset the Homepage setting. In a new window, go to your preferred homepage; in the General prefs tab, click Set to Current Page to set it as your homepage. Use a new window to confirm the setting sticks.