We don’t have to investigate the problem of changing the order of limit and summation in this problem. Here is a more direct way: since $n^2x>nx$ for $n\geq1$ and $x>0$, we have
$$|f(x)|\leq 2\sum_{n=1}^\infty e^{-n^2x}\leq 2\sum_{n=1}^\infty e^{-nx}=2\frac{e^{-x}}{1-e^{-x}}.$$
Now it is obvious that $\lim_{x\to\infty}f(x)=0$.
Change the order of limit and summation. The problem of changing the order of limit and summation is usually converted to the problem of changing the order of limit and integration:
$$f(x)=\sum_{n=1}^\infty F(n,x)=\int_{\mathbb N_{\geq 1}}F(n,x)\,d\mu(n),$$
where $\mu$ is the counting measure on $\mathbb N_{\geq 1}$. By dominated convergence theorem, if $\lim_{x\to\infty}F(n,x)=G(n)$ for all $n$, and
$$|F(n,x)|\leq g(n),\qquad \text{for all }\ n\geq 1, x\ \ \text{large},$$
for some $g$ with $\int_{\mathbb N_{\geq 1}}g(n)\,d\mu(n)=\sum_{n=1}^\infty g(n)<\infty$, then we have
$$\lim_{x\to\infty}f(x)=\lim_{x\to\infty}\int_{\mathbb N_{\geq 1}}F(n,x)\,d\mu(n)=\int_{\mathbb N_{\geq 1}}G(n)\,d\mu(n)=\sum_{n=1}^\infty G(n).$$
Apply to $\sum_{n=1}^\infty e^{-n^2x}e^{ix}$: We have $\lim_{x\to\infty}e^{-n^2x}e^{ix}=0$ for all $n\geq 1$, and
$$|e^{-n^2x}e^{ix}|\leq e^{-n^2},\qquad \forall n\geq 1,x\geq1,$$
and $\sum_{n=1}^\infty e^{-n^2}<\infty$. Therefore, the second paragraph implies that
$$\lim_{x\to\infty} \sum_{n=1}^\infty e^{-n^2x}e^{ix}=\sum_{n=1}^\infty\lim_{x\to\infty}e^{-n^2x}e^{ix}=0.$$
Remark. Dominated convergence theorem (DCT) is a very powerful theorem dealing with the problem of changing the order of limit and integration (we have seen that summation is a special case of integration). You will learn this theorem in Real Analysis course (According to the questions you have asked in this site, I think you haven't learnt that course.)