Wanneer Discourse een identiteitsprovider is, slaat het dan de externe gebruikers-ID's op?

It doesn’t, so you’ll need something custom.

I wonder if it would make more sense to handle this in your Rails app, since it knows the Discourse ID of a user?

You could set up a route like /profile-by-discourse-id/:discourse_id which looks up the relevant user based on the discourse ID and then redirects to the user’s profile in the rails app.