You can use the PHP function number_format()
.
function wpb_total_posts() {
$total = wp_count_posts()->publish;
echo number_format(
$total, // your number
0, // number of decimal points
'.', // decimal point separator
',' // thousands separator
);
}
Or, because you are using the default values anyway, you can shorten the function to:
function wpb_total_posts() {
echo number_format( wp_count_posts()->publish );
}