The Hilbert space of square integral functions contains many functions on which the Hamiltonian is not defined, such as, indeed, discontinuous ones. However, when calculating the time evolution operator on those states where the Hamiltonian exists, one finds it has a unique extension to the entire Hilbert space. Look up stone's theorem:
https://en.wikipedia.org/wiki/Stone%27s_theorem_on_one-parameter_unitary_groups although the mathematical details are quite hairy.
In essence, the above means that time evolution exists for all states, although not all states have an energy!
To make the connection with Fourier series explicit, sines and cosines are nice enough for the Hamiltonian to make sense on them, so one can calculate the time evolution by direct computation. Every function in the Hilbert space can be written as a Fourier series, even the discontinuous ones.
Any state $|\psi\rangle$ in the Hilbert space can be written as a Fourier sum: $|\psi\rangle=\sum_n a_n|f_n\rangle$, where the $a_n$ have to decay faster than $n^{-1/2}$, so that $\langle \psi|\psi\rangle = \sum_n |a_n|^2$ exists. However, for the Hamiltonian to make sense on a state, $\langle H\psi|H\psi\rangle = \sum_n n^4|a_n|^2$, which is clearly not true for all states in the Hilbert space. However, for the time evolution, one has
$\langle U\psi|U\psi\rangle = \sum_n |a_n|^2$, so this exists for all states in the Hilbert space.
Note that the above also shows that "ugly" functions, such as discontinuous ones, have Fourier coefficients that decay slowly, and ones that have many derivatives have coefficients that decay faster.