This is very important: $L^2(0, 2\pi)$ is not the set of square integrable functions on $(0, 2\pi)$. The reason is that the "inner product" on this set is not an inner product: there are nonzero square-integrable functions $f$ such that
$$\langle f, f \rangle = \int_0^{2\pi} |f(x)|^2 \, dx = 0$$
(for example the indicator function of a point). $L^2(0, 2\pi)$ is the quotient of the vector space of square integrable functions by the subspace of functions with the above property, and as a result its elements are not functions, but equivalence classes of functions. This taking of equivalence classes destroys the information of what value a function takes at the endpoints, and in fact destroys the information of what value a function takes on any particular subset of $(0, 2\pi)$ of measure zero, which is why it doesn't matter whether you impose periodicity or not, or whether you work with $(0, 2\pi)$ or $[0, 2\pi]$.
Similarly, the condition that a bunch of functions (really their equivalence classes) forms an orthonormal basis means that certain sequences converge in the $L^2$ sense, and this is much weaker than, and does not imply, pointwise convergence. So a series of periodic functions can converge in the $L^2$ sense to a function that is not periodic.