My understanding is that one of the most important properties of a separable Hilbert space is that we can decompose its elements into generalized Fourier series. For example, consider a set of basis functions $f_n(x)$ that spans the Hilbert space $L^2(\mathbb{R})$. For any function $g(x) \in L^2(\mathbb{R})$, the generalized Fourier series $$\sum_{n = 0}^\infty \langle g, f_n \rangle\, f_n(x), \qquad \qquad \langle g, f \rangle := \int_{-\infty}^\infty g(x)\, f(x)\, dx$$ converges to $g(x)$ in the $L^2$ norm. (Sometimes we can make even stronger statements; for example, for the Hilbert space $L^2([0, 2\pi])$ with the standard basis functions $e^{i n \theta}$, Carleson's theorem guarantees that the (standard) Fourier series above converges to $g(x)$ almost everywhere. As shown here, this is not true in general.)
However, the generalized Fourier series above seems to work much better than we might expect. That is, if we take a function $g(x)$ that does not lie in the Hilbert space and naively consider the above series, it appears to still converge to $g$. For example, the functions $g(x) \equiv 1$ and $g(x) = x^2$ obviously don't lie in $L^2(\mathbb{R})$. Nevertheless, when I try plotting the first few terms of the above generalized Fourier series with the Hermite basis functions, the series does indeed appear (by eye) to approach $g(x)$ more and more closely.
The above generalized Fourier series makes formal sense for any function $g(x)$ such that the inner product $\langle g, f \rangle$ is defined. For basis functions (like the Hermite functions) that lie in Schwartz space, this space of functions $g$ is much larger than $L^2(\mathbb{R})$ and even incorporates some functions that diverge exponentially at infinity. We can't apply the $L^2$ norm to functions $g(x)$ that don't lie in $L^2(\mathbb{R})$, but is there some other sense in which the above generalized Fourier series converges to $g$? If so, why?