Realm has to be a part of user account url. That's built into Keycloak server, and how its service endpoints are structured.
Within your application you can use HttpServletRequest attributes to get to KeycloakDeployment, which contains information about the realm your application was configured with:
KeycloakSecurityContext ctx = (KeycloakSecurityContext) request.getAttribute(KeycloakSecurityContext.class.getName());
KeycloakDeployment deployment = ((RefreshableKeycloakSecurityContext) ctx).getDeployment();
String realm = deployment.getRealm();
You can now use this realm to construct user account URL. I'm not sure if this is part of our public API. There is realm on KeycloakSecurityContext, but that one is only available if user is currently logged in.