The value of 26 ultimately comes from the need to rid the theory of negative-norm states, as previously noted. This involves regularizing (say by multiplying each term by $e^{-\epsilon n}$ and taking $\epsilon\rightarrow 0$ after summing) the sum $ \sum_{n=0}^\infty n, $ which of course diverges. One obtains a finite part equaling $-\frac{1}{12},$ which leads to the 24, and from there to 26 for the number of dimensions (25 space, 1 time). (Analytic continuation of the zeta function gives $\zeta(-1) = -\frac{1}{12} $).
Rather than me writing the details in here, I suggest this nice introductory reference, where the number of dimensions required for consistency of the bosonic string is derived in Ch. 2:

