1 Convenient transformation
The logistic function is often used as a mapping from $(-\infty,\infty)$ to $(0,1)$ (as others mention).
However the logistic function as link function also relates to being the canonical link function, or sometimes it relates to a particular mechanism/model. See the two points below.
2 Canonical link function
In short: the logit of the mean, $\log \left( \frac{p}{1-p} \right) $, is the natural parameter of the Bernoulli distribution. The logistic function is the inverse.
You derive it as follows:
The logit/logistic function relates to the Bernoulli/binary when you express the pdf as an exponential family in canonical form, ie when you use as parameter $\theta$ the natural parameter such that $\eta(\theta) = \theta$:
$$f(y\vert \theta) = h(y)e^{\eta(\theta) t(y) - A(\theta)} = h(y)e^{\theta t(y)- A(\theta)}$$
In the case of the binomial distribution the natural parameter is not the probability $p$ (or $\mu$ which equals $p$), which we typically use, but $\eta = \log \left( \frac{p}{1-p} \right)$
$$f(y\vert p) = e^{\log \left(\frac{p}{1-p}\right)y + \log(1-p)}$$
Then the linear function $X\beta$ is used to model this natural parameter:
$$\eta = \log \left( \frac{p}{1-p} \right) = X\beta$$
If we rewrite it such that $p$ is a function of $X\beta$, then you get
$$p = (1-e^{-X\beta})^{-1}$$
So the logistic function $p=(1-e^{-X\beta})^{-1}$ is the inverse of the logit function $X\beta =\log \left( \frac{p}{1-p} \right)$. The latter pops up in the equation above when we write the model with the natural parameter.
3 Growth model or other differential equation relationship
The above, canonical link function, is an afterthought, and the history of the logistic function is older than when it was recognized as canonical link function. The use of a canonical link function can have advantages but there is no reason that the natural parameter needs to be some linear function.
An alternative reason for the use of the link function can be when it actually makes sense as a deterministic model. For instance in growth models the logistic function can arrise.
When the growth equals
$$f'= f(1-f)$$
Then the solution is the logistic function. You can see the above as exponential growth when $1-f\approx 1$ that becomes limited when $f$ approaches $1$.