Get an array of custom taxonomy with posts inside each items

$terms = get_terms( 'custom_taxonomy', array(
    'hide_empty' => false,
));

foreach( $terms as $term ) {
    $args = [
        'post_type'   => 'custom_post_type', 
        'post_status' => 'publish',
        'tax_query'   => [
            [
                'taxonomy' => 'custom_taxonomy',
                'field'    => 'id',
                'terms'    => $term->term_id,
            ]
        ]
    ];

    $posts = new WP_Query( $args );

    $result[ $term->term_id ] = $posts->posts;

}

In result you will have associative array with

$result[ TERMID_1 ] = ARRAY( POST_OBJECT_OF_TERMID_1 );

$result[ TERMID_2 ] = ARRAY( POST_OBJECT_OF_TERMID_2 );

$result[ TERMID_3 ] = ARRAY( POST_OBJECT_OF_TERMID_3 );