Group by custom field value (start and end times)

try this wich first stack all posts with same times

$tabEvent = [];

foreach ( $rand_posts as $post ) {
    setup_postdata( $post );

    $start_time = get_field("start_time");
    $end_time = get_field("end_time");


    $index = "$start_time|$end_time";


    // store all the posts with same times

    if (!isset($tabEvent[$index])) {
        $tabEvent[$index] = [];
    }

    $tabEvent[$index][] = $post;

}

foreach ($tabEvent as $index => $listeEvent ) {

    echo "<h2>$index<h2/>";


    foreach ($listeEvent as $post) {

        // all posts with the same times

        echo "<h3>{$post->post_title}<h3/>";

    }

}