I'm trying to solve this problem.
There is a language $L = \{f\}$ with equality (we can use '$=$'), where $f$ is a unary function.
Our goal is to decide and prove, whether there is a theory $T$, such that for any realisation $\mathbf{M}$ of language $\mathcal{L}$ stands:
$$ \begin{array}{lrcl} \mbox{(a)} & M \models T &\iff& \mbox{range of f is finite} \\ \mbox{(b)} & M \models T &\iff& \mbox{range of f is infinite} \end{array} $$ I think that I've solved the first question a) finite but I'm not sure:
a) yes, there exists such theory Prove: $ T = \{ \exists y \forall x(f(x)=y) \}$
This theory consists of 1 formula which forces that the range of $f$ is finite.
b) I don't have an idea. The only thing I can say is that $U$ (universe) should be infinite because otherwise, the range of $f(x)$ would be finite.
I suppose that there is no chance to find a theory which satisfies b) but I'm not sure and I can't prove it.
Originally, from your attempts, it seemed that you were looking for a theory that only has (a') finite or (b') infinite models, for which your answer to (a') works and one can answer (b') by noting that a function $f$ from $U$ to $U$ that is one-to-one (injective) and not onto (not surjective) cannot have a finite range.
Now, it seems you want (a) a $T$ that characterises the models where $f$ has a finite range and (b) a $T$ that characterises the models where $f$ has an infinite range. The answer to (a) is that no such $T$ exists, which can be proved using something called the compactness theorem that I suspect you haven't studied yet. For (b) such a $T$ does exist: for $n = 2, 3, \ldots$, let $\phi_n(x_1, \ldots x_n)$ be a frmula with free variables $x_1, \ldots, x_n$ that asserts that the $x_i$ are pairwise distinct. (I leave it to you to design $\phi_n$.) Then take $T$ to comprise the infinite lists of sentences: $$ \exists x_1 \exists x_2\,\phi_2(f(x_1), f(x_2)) \\ \exists x_1 \exists x_2\exists x_3\,\phi_3(f(x_1), f(x_2), f(x_3)) \\ \vdots \\ \exists x_1 \ldots \exists x_n\, \phi_n(f(x_1), \ldots, f(x_n))\\ \vdots $$