The very short answer is "analytic continuation": we can begin with definitions that are only well-defined on some subset $A \subseteq \mathbb{C}$, find an analytical relation that holds within $A$, and then if one side of this relation is valid on a larger set $B \supseteq A$, use that to define an extension into $B$. I'll provide a Gamma function example, since it complements your question.
We can define, for $\Re(z) > 0$, $\Gamma(z)$ as
$$\Gamma(z) = \int_0^\infty e^{-t} t^{z-1} \; dt$$
Using this relation, we can show that
$$\Gamma(z+1) = z \Gamma(z) \implies \Gamma(z) = \frac{\Gamma(z+1)}{z}$$
Now note that while our original definition of $\Gamma$ is only valid for $\Re(z) > 0$, the right-hand side of our new relation defines an analytical (strictly, meromorphic) function on $\Re(z) > -1, z \neq 0$.
This lets us analytically continue our original equation for $\Gamma$ into a larger subset of $\mathbb{C}$. Moreover, we can repeat this trick to extend it to all $z \in \mathbb{C} \setminus \lbrace 0, -1, -2, \dots \rbrace$. We started with a definition of an analytic function on $\Re(z) > 0$, and ended up defining an analytic function on almost all of $\mathbb{C}$.
This is more or less your question: by analytically continuing our expression, we can "sensibly" assign a value to our original non-convergent expression.
A similar example is how $\zeta(-1) = -\frac{1}{12}$. The starting point for our definition of $\zeta(z)$ does not converge for $z = -1$, but we can analytically continue it to a larger function which is finite at $-1$, where it takes the value $-\frac{1}{12}$. But of course, this does not mean that
$$\sum_{n=1}^\infty n = -\frac{1}{12}$$
For a final example, consider how the series
$$f(x) = 1 + x + x^2 + \dots$$
converges for $\lvert x \rvert < 1$. On this domain, we can show that
$$f(x) = \frac{1}{1-x}$$
This is valid on a larger domain, and we can evaluate, say,
$$f(2) = -1$$
but we can't back-substitute this into our original expression
$$1 + 2 + 2^2 + \dots \neq -1$$
Instead, the (roughly) correct statement is that any analytical function that agrees with our original series on $\lvert x \rvert < 1$ and is valid on a larger domain (for avoidance of certain cases, let's say it's "suitably nice", say path connected) containing $2$, will have $f(2) = -1$.