First, I don't think you actually asked what you meant to ask. I'll answer what you actually asked, and then comment on what I think you meant to ask.
You are correct that if $\lim\limits_{x\to a}f(x) = k\in\mathbb{R}$ and $g$ is continuous at $k$, then
$$\lim_{x\to a}\;g(f(x)) = g\left(\lim_{x\to a}f(x)\right) = g(k);$$
and this also holds if $a$ is replaced by $\infty$ or $-\infty$.
It gets a bit trickier if the limit of $f$ is $\infty$ or $-\infty$; for one thing, it no longer makes sense to write $g(\lim\limits_{x\to a}f(x))$, so instead we must talk about $\lim\limits_{t\to\infty}g(t)$. But even with that correction, we do not have an easy criteria for when it makes sense to "plug in"; here are two propositions and one example along those lines.
Proposition 1. If $\lim\limits_{x\to a}f(x) = \infty$, and $\lim\limits_{t\to\infty}g(t) = k\in\mathbb{R}\cup\{\infty,-\infty\}$, then $\lim\limits_{x\to a}\;g(f(x))=k$.
Proof. Suppose $\lim\limits_{t\to\infty}g(t) = k$. First, take $k\in\mathbb{R}$. We show that $\lim\limits_{x\to a}\;g(f(x)) = k$. Let $\epsilon\gt 0$. Then there exists $M\gt 0$ such that if $t\gt M$, then $|g(t)-k|\lt \epsilon$. Since $\lim\limits_{x\to a}f(x) = \infty$, there exists $\delta\gt 0$ such that if $0\lt |x-a|\lt \delta$, then $f(x)\gt M$. Thus, if $0\lt |x-a|\lt \delta$, then $f(x)\gt M$, hence $|g(f(x))-k|\lt\epsilon$. Therefore, $\lim\limits_{x\to a}\;g(f(x)) = k$, as claimed.
Now consider the case $k=\infty$. Let $N\gt 0$; then there exists $M\gt 0$ such that if $t\gt M$, then $g(t)\gt N$. Since $\lim\limits_{x\to a}f(x)=\infty$, there exists $\delta\gt 0$ such that if $0\lt |x-a|\lt \delta$, then $f(x)\gt M$; hence $g(f(x))\gt N$ whenever $0\lt |x-a|\lt \delta$, proving that $\lim\limits_{x\to a}\;g(f(x))=\infty$. The same argument holds if $k=-\infty$. QED
The result also holds if $a$ is replaced with $\infty$ or $-\infty$.
The converse doesn't work in general:
Example: Functions $f$ and $g$, with $g$ continuous everywhere (in fact, uniformly continuous), $\lim\limits_{x\to a}f(x)=\infty$, $\lim\limits_{x\to a} \;g(f(x))$ exists, and $\lim\limits_{t\to\infty}g(t)$ does not exist.
Let $f(x) = \lfloor x\rfloor\pi$, $g(t)=\sin(t)$, $a=\infty$. Then $\lim\limits_{x\to \infty}\;g(f(x))=0$, but $\lim\limits_{t\to\infty}g(t)$ does not exist, nor is it equal to $\infty$ or $-\infty$. It is not hard to come up with similar examples with $a\in\mathbb{R}$. QED
On the other hand, with a bit more information, we have:
Proposition 2. Let $f$ and $g$ be functions, and assume that:
- $\lim\limits_{x\to a}f(x)=\infty$; and
- For every $\delta\gt 0$ there exists $M_{\delta}\gt 0$ such that $(M_{\delta},\infty)\subseteq f\Bigl( (a-\delta,a)\cup(a,a+\delta)\Bigr)$.
If $\lim\limits_{x\to a}\;g(f(x))=k\in\mathbb{R}\cup\{\infty,-\infty\}$, then $\lim\limits_{t\to\infty}g(t) = k$.
Proof. We do the case $k\in\mathbb{R}$; the other two cases are similar. Let $\epsilon\gt 0$. Then there exists $\delta\gt 0$ such that if $0\lt|x-a|\lt \delta$, then $|g(f(x))-k|\lt\epsilon$.
By (2), there exists $M_{\delta}$ such if $t\gt M_{\delta}$, then there exists $x\in (a-\delta,a)\cup(a,a+\delta)$ with $f(x)=t$.
Therefore, if $t\gt M$, then there exists $x$, $0\lt |x-a|\lt \delta$ such that $g(t) = g(f(x))$, hence $|g(t)-k| = |g(f(x))-k|\lt \epsilon$, with the last inequality by choice of $\delta$. Therefore, $\lim\limits_{t\to\infty}g(t)=k$, as claimed. QED
Similar results hold if we replace $a$ with $\infty$ or $-\infty$.
Corollary. Let $f$ and $g$ be functions with $\lim\limits_{x\to a}f(x) =\infty$ and $\lim\limits_{x\to a}\;g(f(x))=k\in\mathbb{R}\cup\{\infty,-\infty\}$. If $f$ is continuous on an open punctured neighborhood of $a$, then $\lim\limits_{t\to\infty}\;g(t)=k$.
Proof. If $f$ is continuous on an open punctured neighborhood of $a$, then the condition that $f(x)\to\infty$ as $x\to a$ ensures that $f$ satisfies condition 2 of Proposition 2. QED
In fact, it's enough that $f$ be continuous on either an interval of the form $(a-\delta_f,a)$, or on an interval of the form $(a,a+\delta_f)$.
Continuity can even be weakened further:
Corollary. Let $f$ and $g$ be functions with $\lim\limits_{x\to a}f(x)=\infty$ and $\lim\limits_{x\to a}\;g(f(x))=k\in\mathbb{R}\cup\{\infty,-\infty\}$. If there exists $\delta_f\gt 0$ such that $f$ has the intermediate value property on either $(a-\delta_f,a)$ or on $(a,a+\delta_f)$, then $\lim\limits_{t\to \infty} g(t) = k$.
Proof. Assume that $f$ has the intermediate value property on $(a-\delta_f,a)$; the other case is similar. We prove that $f$ satisfies condition (2) of Proposition 2.
Let $\delta\gt 0$; we may assume that $\delta\leq\delta_f$.
Let $M=f(a-\frac{\delta}{2})$; let $z\gt M$. Since $\lim\limits_{x\to a}\;f(x)=\infty$, there exist $x_1$, $a-\frac{\delta}{2}\lt x_1 \lt a$ such that $f(x_1)\gt z$. Since $f$ has the intermediate value property on $(a-\delta,a)$ and $f(a-\frac{\delta}{2})\lt z\lt f(x_1)$, we can find $x_2\in (a-\frac{\delta}{2},x_1)$ such that $f(x_2)= z$; thus, $z\in f(a-\delta,a)$. This proves that for all $z\gt M$, $z\in f(a-\delta,a)$, hence $(M,\infty)$ is contained in the image and Condition (2) of Proposition 2 holds; conclusion of the corollary now follows from Proposition 2. QED
Note that in my example above, $f$ does not have the intermediate value property, which is what leads to problems.
That said: the real issue with your example lies in the indeterminate form $\infty-\infty$, rather than a problem with "plugging in", I think.
Instead, what you are dealing with here is an attempt at applying the limit laws that say, for example, that the limit of a difference is the difference of the limits:
If $\lim\limits_{x\to a}f(x) = L$ and $\lim\limits_{x\to a}g(x)=M$, then $\lim\limits_{x\to a}\Bigl(f(x)-g(x)\Bigr) = L-M$.
If we try to extend this (and related results on sums, products, and quotients) to the cases where limits are equal to $\infty$ or $-\infty$, then you have to deal with the extended reals, $\mathbb{R}\cup\{\infty,-\infty\}$. The problem here is that not every operation among extended reals is well-defined. Some operations are well defined and the limits laws work for them:
- $\infty+a = \infty$ for all real numbers $a$;
- $-\infty+a = -\infty$ for all real numbers $a$;
- $\pm\infty\times a =\pm\infty$ if $a\gt 0$ or $a=\infty$;
- $\pm\infty\times a = \mp\infty$ if $a\lt 0$ or $a=-\infty$;
- $\frac{\pm\infty}{a} = \pm\infty$ if $a\gt 0$;
- $\frac{\pm\infty}{a} = \mp\infty$ if $a\lt 0$;
- $\frac{a}{\pm\infty} = 0$.
But other expressions are indeterminate forms: the limit laws don't apply to them. They don't apply to expressions like $\infty-\infty$ or $\frac{\infty}{\infty}$ (just like they don't apply in the real numbers to expressions like $\frac{a}{0}$).
So the problem is not one of "plugging in", but rather that the mistake you mention lies in trying to apply the limit laws and forgetting that $\infty-\infty$ is an indeterminate form and not an operation that can be performed.