You can follow the instructions in this Apple Support Topic:
What to do before you sell or give away your Mac - Apple Support
But it sounds like you may just need to troubleshoot Safari:
First, check to see if Safari is in System Preferences > Users & Groups > Login Items. If it is remove it by using the ➖ button. Also check to see if when you choose Apple Menu > Log Out, Shutdown, or Restart that "Reopen windows..." is not check marked.
Then try these tips:
Force Quit Safari ( command + option + esc keys). Then restart Safari holding the Shift key.
Turn off Safari extensions in Safari > Preferences > Extensions > un-checkmark all extensions.
Empty Caches. You can either choose Safari menu > Clear History Or, if you do not want to remove History go to Safari menu > Preferences > Advanced and check the “Show Develop Menu” in Menubar. Then, on that menu > “Empty Caches”.
See these Apple Support Topics for detailed advice:
If Safari is slow, stops responding, quits unexpectedly, or has other issues - Apple Support
If Safari doesn't load a page or webpage items are missing - Apple Support
Safari for Mac: If Safari can’t open a website