How do I use different domain for subdomains in WP Multisite?

Let’s establish the baseline: it is possible to have the main site in example-domain-x.com and all subsites subdomains in example-domain-y.com. You just add subdomain1.example-domain-y.com (or subdomain2.example-domain-y.com, subdomain3.example-domain-y.com) like you would be adding a bare or www domain in the domain mapping panel ( URL containing wp-admin/network/settings.php?page=dm_domains_admin ).

annotated domain mapping screen in a WordPress Multisite

To achieve the same programmatically, you could hook a function to wp_normalize_site_data filter and change the domain in the data array.

add_filter('wp_normalize_site_data','wpse38196_wp_modify_domain_new_site');

function wpse38196_wp_modify_domain_new_site($data){
    // $data is an array, the same from wp_insert_site. See https://developer.wordpress.org/reference/functions/wp_insert_site/
    $original_domain = $data['domain'];x§   
    $data['domain'] = str_replace('mymainsite.com', 'subdomains.com', $data['domain']);
    return $data;
}

I presume you are aware, but in any case, you will also need to take care of setting up a new domain and SSL certificates in your HTTP server (i.e. apache, nginx), any reverse proxy (e.g. NGINX, Varnish, Cloudflare) and DNS server. This could be more harder to do proprogrammatically, including because the steps for doing change according to the setup.