Purchase and install Homecoming for Mastodon in the App Store.
Open the Extensions tab of the Preferences window in Safari.
The "Enable in Safari…" command in Homecoming for Mastodon does this automatically.
Otherwise, you can open Safari manually and select "Preferences…" from the "Safari" menu in the main menu bar.
In the Extensions tab of the Safari Preferences window, check the box next to Homecoming for Mastodon to enable it.
Open a Safari window and click the Homecoming for Mastodon extension icon in the toolbar.
Enter the domain of your Mastodon instance and save. (Homecoming for Mastodon may autofill the domain from the open web page, but you still need to save.)
Now whenever you're browsing a web page on another Mastodon instance, you can just click the Homecoming for Mastodon extension icon in the toolbar.
The page opens in your own Mastodon instance. This works for any Mastodon URL, including profiles and posts!
You only need to enable Homecoming for Mastodon once in Safari, and then it will remain enabled permanently. It will remain enabled even after you install new versions of Safari and Homecoming for Mastodon. If you ever need to disable Homecoming for Mastodon, just uncheck the box in Safari Preferences.
Keyboard Shortcut: Homecoming for Mastodon has the keyboard shortcut Control-Command-M in Safari. This is equivalent to clicking the extension toolbar button. Unfortunately, Safari does not support changing the keyboard shortcut.
If you're having trouble enabling the extension in Safari Preferences because the checkboxes don't respond to clicks, please see the Apple support document on this subject. For more details, see my article Safari bug: can't enable extensions on Catalina.
If Homecoming for Mastodon is missing in Safari Extensions Preferences on macOS, this may be a macOS bug with Launch Services. To restore the extension: quit Safari, copy the following command, and paste it into the Terminal app (located in the Utilities subfolder of the Applications folder):