I've had similar issues with Mastodon. You can mention people, you can boost and reply to posts, etc., you can link to a post on the same server, and Mastodon will adapt the links just fine. But if you link to an individual post on another instance, it jumps out of Mastodon and opens the web page directly.
It looks like there is a feature request for Lemmy to fix this, but it hasn't been touched in a while.
That said: clicking on a link to another instance shouldn't actually log you out of your own. If you come back to your instance, you should still be logged in.