It has to do with sums of infinite series.
In the first joke, the bartender thinks what’s coming is fractional powers of two. The sum of 1 +1/2 + 1/4 + 1/8 + 1/16 + … = 1/2^0 + 1/2^1 + 1/2^2 + 1/2^3 + 1/2^4 + … = 2. That is, the sum of the series converges to 2. So he slams two beers to finish the sum rather than infinitely pouring smaller and smaller beers.
In the second joke, before the bartender can cut them off, the third mathematician reveals a different series: 1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 + … = ∞. That is, the sum of the series diverges. So there’s no skipping to the end. The bartender has to just keep pouring smaller and smaller beers forever.