get_the_category()
returns an array of WP_Term
objects, so you already have access to the count
property – just sort the array by it and retrieve the one with the highest count:
$main_category = current( wp_list_sort( get_the_category(), [ 'count' => 'DESC' ] ) );
Check out the documentation for wp_list_sort()