I think $T$ is always an ideal of $C(X)$.   

First note that the  condition $f\in T$ may be rephrased as: $f$ possesses a zero in any infinite closed subset $C\subset X$. Indeed, if $f\notin T$, there is $g\in C(X)$ for which the closed set  $C:=\{fg=1\}$ is infinite and $f$ has no zero there. Conversely, if $C$ is a closed subset of $X$  where $f$ does not vanish, we can extend $1/f_{|C}$  to a $g\in C(X)$, therefore such that   the set $\{fg=1\}$ is infinite.

As a consequence we have that any  $f\in T$  (i)  vanishes on any  accumulation point $x$ of $X$  (because if $f(x)\neq 0$ then $f$ would be non-zero in a closed nbd ox $x$,  an infinite set). Moerover  (ii) on any  closed discrete subset $C$ of $X$, $f$ is different from zero only on finitely many points (because any subset of $C$, in particular $\{f\neq0\}\cap C$ is closed in $C$ and also in $X$). Conversely, any $f$ in $C(X)$ verifying (i) and (ii) necessarily has a zero in any infinite closed set (indeed, any  infinite closed set of $X$ either possesses an accumulation point, thus a zero of $f$ by (i), or is discrete, and has a zero by (ii)).

In conclusion, $f\in T$ if and only if $D(X)\subset\{f=0\}$ and for any discrete closed set $C$ $\{f\neq0\}\cap C$ is finite; from this characterization it follows plainly that $T$ is an ideal of $C(X)$.