How to get posts that contain multiple terms from multiple taxonomies?

I suggest that that @SallyCJ’s approach makes much more sense if you can do it this way: simply break down wherever these ID’s get written to store the tax names at that point.

However it seems like figuring out which Taxonomy each Term ID is in and then using that to generate the tax_query part of the WP_Query args isn’t so hard. get_term allows you to find the taxonomy name from a term ID, so with that you’re half way there.

This is untested code, some of it may contain errors and uses your $args as a base so you may need to double check the structure of the tax_query part, but it contains all the pieces you could use to build the code if you wanted to do it this way:

$arrTermIDs = [ 1,2,3,4,5 ];
$arrTaxAndTerms = []; // make a 2d array with the term ID's broken down by tax name

foreach ($arrTermIDs as $termID) {
    $term = get_term($termID);
    if (!in_array($term->taxonomy, $arrTaxAndTerms)) 
        $arrTaxAndTerms[$term->taxonomy] = [] ; // create array for this tax if we don't have one already
    
    $arrTaxAndTerms[$term->taxonomy][] = $termID; // add this term id to array for this tax
}

// Now we have all the info we need to build the tax_query items for each taxonomy 
$arrTaxQueryItems = [];

foreach($arrTaxAndTerms as $taxName => $termIDs) {
    $arrTaxQueryItems[] = 
        array(
              'taxonomy' => $taxName,
              'field'    => 'term_id',
              'terms'    => $termIDs
        );
}

// Put that together into your $args:
$args = array(
    'numberposts' => -1,
    'post_type' => array('post'),
    'post_status' => 'publish',
    // any other conditions you want here
    'tax_query' => array(
         'relation' => 'AND',
         $arrTaxQueryItems
    )
)