I haven't seen this presented as a theorem in a textbook.
Well, this issue is treated in Protter's book (see from theorem 2.7 to theorem 2.17(a)). A general result can be stated as follows.
Theorem of change of variables in limits: Let $\alpha,\beta,\gamma$ represent real numbers, $\infty$ or $-\infty$. We have
$$\lim_{x\to\alpha} f(g(x))=\lim_{y\to \beta}f(y),\quad\text{where}\quad \beta=\lim_{x\to\alpha} g(x),$$
provid that $\displaystyle\lim_{y\to \beta}f(y)=\gamma$ and at least one of the following conditions is satisfied:
- $\beta,\gamma\in \mathbb R$ and $f$ is continuous at $\beta$.
- $\beta\in\mathbb R$ and $g(x)\neq \beta$ in a punctured neighbourhood of $\alpha$.
- $\beta=\infty$ or $-\infty$.
The same result is valid for one-sided limits.
Remark: Hipotesis 1, 2 or 3 are not superfluous since the existence of $\displaystyle\lim_{y\to \beta}f(y)$ is not enough to ensure the validity of the result. Take, for example, $\alpha=\beta=0$, $\gamma=1$, $g(x)=x\sin(1/x)$ and $f(x)=\left\{\begin{aligned}&2,\quad x= 0\\&1,\quad \text{otherwise}\end{aligned}\right.$. Then, $\displaystyle \lim_{x\to \alpha}g(x)=\beta$ and $\displaystyle \lim_{y\to \beta}f(y)=\gamma$. However, the result does not hold because $\displaystyle \lim_{x\to \alpha}f(g(x))$ does not exist: $f(g(x))=\left\{\begin{aligned}&2,\quad x= \tfrac{1}{n\pi}\text{ with }n\in\mathbb Z^*\\&1,\quad \text{otherwise}\end{aligned}\right.$ so that the function jumps from $1$ to $2$ near zero.
Proof: We prove it for two-sided limits. The proof for one-sided is similar.
Suppose that condition 1 is satisfied. Here, we can have $\alpha$ real, $\infty$ or $-\infty$. We suppose that $\alpha$ is real. If $\alpha=\infty$ or $-\infty$ the argument is similar, with the used definition of limit replaced by the appropriate one.
Since $f$ is continuous at $\beta$, given $\varepsilon>0$, there exists $\delta>0$ such that $|y-\beta|<\delta$ implies $|f(y)-f(\beta)|<\varepsilon$. Since $\displaystyle \lim_{x\to\alpha} g(x)=\beta$, given $\tilde{\varepsilon}>0$, there exists $\tilde{\delta}>0$ such that $0<|x-\alpha|<\tilde{\delta}$ implies $|g(x)-\beta|<\tilde{\varepsilon}$. Taking $\tilde{\varepsilon}=\delta$, we see that $0<|x-\alpha|<\tilde{\delta}$ implies $|g(x)-\beta|<\delta$, which implies $|f(g(x))-f(\beta)|<\varepsilon$. Therefore, $\displaystyle\lim_{x\to\alpha}f(g(x))=f(\beta)=\gamma=\lim_{y\to \beta} f(y)$.
Suppose that condition 2 is satisfied. Here, we can have $\alpha$ as well as $\gamma$ real, $\infty$ or $-\infty$. We suppose that $\gamma$ is real and $\alpha=\infty$. In the other cases, the arguments are similar (just replace the definition of limit).
Since $\displaystyle\lim_{y\to \beta}f(y)=\gamma$, given $\varepsilon>0$, there exists $\delta>0$ such that $0<|y-\beta|<\delta$ implies $|f(y)-\gamma|<\varepsilon$. Since $\displaystyle \lim_{x\to\infty} g(x)=\beta$, given $\tilde{\varepsilon}>0$, there exists $\tilde{\delta}>0$ such that $x>\tilde{\delta}$ implies $|g(x)-\beta|<\tilde{\varepsilon}$, which implies $0<|g(x)-\beta|<\tilde{\varepsilon}$. Taking $\tilde{\varepsilon}=\delta$, we see that $x>\tilde{\delta}$ implies $0<|g(x)-\beta|<\delta$, which implies $|f(g(x))-\gamma|<\varepsilon$. Therefore, $\displaystyle\lim_{x\to\infty}f(g(x))=\gamma=\lim_{y\to \beta} f(y)$.
Suppose that condition 3 is satisfied. Here $\beta=\infty$ or $-\infty$ and, again, we can have $\alpha$ as well as $\gamma$ real, $\infty$ or $-\infty$. We suppose that $\beta=\gamma=\alpha=\infty$. The other cases are similar.
Since $\displaystyle\lim_{y\to \infty}f(y)=\infty$, given $\varepsilon>0$, there exists $\delta>0$ such that $y>\delta$ implies $f(y)>\varepsilon$. Since $\displaystyle \lim_{x\to\infty} g(x)=\infty$, given $\tilde{\varepsilon}>0$, there exists $\tilde{\delta}>0$ such that $x>\tilde{\delta}$ implies $g(x)>\tilde{\varepsilon}$. Taking $\tilde{\varepsilon}=\delta$, we see that $x>\tilde{\delta}$ implies $g(x)>\delta$, which implies $f(g(x))>\varepsilon$. Therefore, $\displaystyle\lim_{x\to\infty}f(g(x))=\infty=\lim_{y\to \infty} f(y)$. $\square$