All those services use a protocol named WebFinger that allows for having the servers in different domains but showing the users as being in a main domain. For example, my self-hosted Synapse server is at matrix.domain.tld, but my users are all like [email protected].
Unfortunately I don't really know how to set it all up manually, I just let Yunohost take care of managing it.