I know there's a theorem that states that for $f\in L^{1}(\mathbb{R})$ we have $f(x)= \frac{1}{2 \pi} \int \hat{f} (k) e^{ikx} dk$ (or something similar, it depends on how you define the Fourier transform). I think the proof I have seen uses $C^{\infty}_0 $ functions (smooth functions with compact support), and even though it doesn't use them, I'm sure it uses a dense subspace of $L^1$. Now, if I consider the Fourier series, I have that for $f\in L^1([0,2 \pi])$ and periodic, then $f(x)= \frac{1}{2\pi} \sum_{k\in \mathbb{Z}} \hat{f}(k) e^{ikx}$. But this isn't true for every $f$, for instance the Fourier series of some continuous functions doesn't converge (maybe it even diverges?).
The question is: given the fact that for $f\in C^1$ the convergence is uniform (total in fact), why can't I conclude that for all functions in $L^1([0,2 \pi])$? Why can't I use the same density argument used for the Fourier inverse theorem?
First of, it is not true that the fourier inversion formula holds for any $f\in L^1(\mathbb{R}$. To see this, you have $f\in L^1$ such that $\widehat{f} \notin L^1$: Just take indicator function of finite symmetric interval, the fourier transform is (up to a constant) just an inflation of $\frac{\sin x}{x}$, which is not summable, and so the inversion formula is not meaningful in any ordinary (function-wise) way.
Second, Yes, some fourier series diverge (and infact, once you find one that diverges then you can make it diverge quite alot). But to see why the formula doesn't work, or rather, why knowing it works for very good functions does not imply it works for other functions, we must see where it should fail more carefully.
Denote a sequence of functions $f_n \in L^1([-\pi ,\pi])$ for $n=1,2,\ldots$ and also suppose they are very good, meaning they are $C^\infty$. Then they equal their fourier series, we have
$$f_n (x)= \sum_{k\in \mathbb{Z}} c^{(n)}_k \mathrm{e} ^{ikx}$$ where $c^{(n)}_k = \widehat{f_n} (k)$. Further suppose we have $f_n \rightarrow f$ in some topology. We will try to figure out what is this topology later. Then when can we say that $f$ equals its fourier series?
First suppose we have just $f_n \rightarrow f$ in $L^1$. This is the first reasonable thing to say, since all we know is $f\in L^1$. Then we can get that $\widehat{f_n}(k) \rightarrow \widehat{f}(n)$ uniformally, that is, independent of $n$, indeed:
$$\left|\int_\mathbb{T} f_n(x)\mathrm{e}^{-inx} \mathrm{d}x - \int_\mathbb{T} f(x)\mathrm{e}^{-inx} \mathrm{d}x \right| \leq \int_\mathbb{T} |f_n(x)-f(x)| \mathrm{d}x \rightarrow 0 $$ So the series converge, but $f_n(x)$ does not necessarily converge to $f(x)$! So equality could not hold unless further details are given. Then we must improve our assumptions on the convergence of $f_n$ to $f$, but this will obviously improve our conditions of $f$, that is to say that not every function $f\in L^1([-\pi,\pi])$ can be the limit of such good functions.