How to apply these filters

You need to return the value in the function for it to be accessible outside that function

function comparelimit( $location ) {
    $location = 10;
    return $location;
}
add_filter( 'woocommerce_products_compare_max_products', 'comparelimit' );