The regularity theorem which states that if $\color{blue}{f\in L^2(\Omega)}$ and
$$
\color{blue}{\int_{\Omega}\nabla u\nabla \varphi\,\mathrm{d}x=\int_{\Omega} f\varphi\,\mathrm{d}x\quad \forall \varphi\in H^{1}(\Omega)}\implies\color{blue}{u\in H^2(\Omega)}
\tag{PR}\label{pr}
$$
is true if and only if some regularity conditions on the boundary of the domain $\partial \Omega$ and on the boundary value of the solution $u$ are assumed (be it a Dirichlet, Neumann or Robin boundary value problem). Otherwise, as @ArcticChar states, you can only expect $u\in H_\mathrm{loc}^2(\Omega)$.
Precisely
- Valentin Mikhailov, in his textbook [2] at paragraph §2.3 pp. 216-226, proves the $H^k$, $k\in\Bbb N_+$ regularity of the solution of problem \eqref{pr} assuming $\color{red}{\partial\Omega\in C^2}$, $\color{red}{f\in H^k(\Omega)}$ and the following boundary conditions
$$
\text{(Dirichlet) }
u|_{\partial\Omega}=g\in H^{k+1/2}(\partial\Omega)
\quad\text{or}\quad\text{(Neumann)}
\begin{cases}
\left.\dfrac{\partial u}{\partial \nu}\right|_{\partial\Omega}=g\in H^{k+1/2}(\partial\Omega)\\
\\
\displaystyle{\int_\Omega f(x)\mathrm{d}x=\int_{\partial\Omega} g(x)\mathrm{d}x}
\end{cases}
$$ and proves the result directly, giving also some indication on how to dealwith the Robin boundary condition.
- Pierre Grisvard, in his famous monograph [1] at paragraph §2.1 pp. 83-84, states that the solution $u$ of problem \eqref{pr} is $W^{2,p}(\Omega)$, $1<p<+\infty$, provided that $\color{red}{\partial\Omega\in C^{1,1}}$, $\color{red}{f\in L^p(\Omega)}$ and that the following boundary conditions hold
$$
\text{(Dirichlet) }
u|_{\partial\Omega}\in W^{2-\frac{1}{p},p}(\partial\Omega)
\quad\text{or}\quad\text{(Robin) }\,\left.\gamma\left(
\frac{\partial u}{\partial \nu}+\sigma u\right)\right|_{\partial\Omega}\in W^{2-\frac{1}{p},p}(\partial\Omega)
$$ but does not proves the result directly (he proves it for a more general divergence form operator) and also considers the Neumann boundary condition explicitly only for the Helmoltz operator. Due to this, below we will follow Mikhailov's development.
The first step of Mikhailov is to prove the theorem with homogeneous boundary conditions:
Theorem 4 ([2], p. 217). If $f\in H^k(\Omega)$ and $\partial\Omega\in C^{k+2}$ for certain $k\ge 0$, then the generalized solutions $u(x)$ of the first and second boundary-value problems (respectively called Dirichlet and Neumann problems) with homogeneous boundary condition for the Poisson equation belong to $H^{k+2}(\Omega)$ and satisfy (in the case of the second boundary problem it is assumed that $\int_\Omega u \mathrm{d}x=0$) the inequality
$$
\Vert u\Vert_{ H^{k+2}(\Omega)}\le C\Vert f\Vert_{ H^{k}(\Omega)}
$$
where the constant $C>0$ does not depend on f.
Then he uses the regularity theorem 4 above to the case of non homogeneous boundary conditions ([2], p. 226) by reducing to homogeneous ones. He explicitly does this only for the Dirichlet problem as we do, but the same method nevertheless works for the Neumann problem, as shown in this answer. Consider a solution $u(x)$ of the problem Dirichlet problem above and a function $\Phi\in H^{k+2}(\Omega)$ whose trace on $\partial\Omega$ is $g\in H^{k+1/2}(\partial\Omega)$, i.e.
$$
\Phi=g\;\text{ on }\;\partial\Omega\label{1}\tag{1}
$$
Define $w=u-\Phi$: then, for every $\varphi\in H^{1}_0(\Omega)$,
$$\label{GeneralizedDirichlet}\tag{GN}
\begin{split}
\int_{\Omega} \nabla w \cdot \nabla \varphi \, \mathrm{d}x&=\int_{\Omega} \nabla u \cdot \nabla \varphi \, \mathrm{d}x - \int_{\Omega} \nabla \Phi \cdot \nabla \varphi \, \mathrm{d}x \\
&= \int_\Omega f \varphi \, \mathrm{d}x + - \int_{\Omega} \nabla \Phi \cdot \nabla \varphi \, \mathrm{d}x \\
&=\int_\Omega f \varphi \, \mathrm{d}x - \int_{\Omega} \nabla\cdot(\varphi\nabla\Phi) \, \mathrm{d}x + \int_{\Omega} \varphi\Delta\Phi \, \mathrm{d}x \\
&=\int_\Omega \big[\,f + \Delta\Phi\big]\varphi\, \mathrm{d}x ,
\end{split}\label{2}\tag{2}
$$
thus we get
$$
\int_{\Omega} \nabla w \cdot \nabla \varphi \, \mathrm{d}x=\int_\Omega f_1 \varphi \, \mathrm{d}x
$$
where $f_1=f+\Delta\Phi\in H^k(\Omega)$. This means that $w$ solves the homogeneous Dirichlet problem with homogeneous boundary conditions (i.e. $g\equiv 0$), and by applying theorem 4 we have
$$
w=u-\Phi\in H^{k+2}(\Omega) \iff u=w+\Phi\in H^{k+2}(\Omega)
$$
Notes
- In Mikhailov's notation, $H^0=L^2$: also he does not use the standard notation for traces, for example expressing that $\varphi\in H^{1/2}(\partial G)$ by saying that $\varphi$ is a function in $L^2(\partial G)$ which is the trace of a function $\Phi\in H^1(G)$.
- Why it is necessary to consider first the homogeneous boundary value problem and then reducing the non homogeneous one to it? Possibly because of the Prym-Hadamard phenomenon, i.e. because there exists functions $g\in C^0(\partial\Omega)$ which are not extendible as $\Phi\in H^1(\Omega)$
- As stated above, assuming $f\in L^2(\Omega)\cap H^{k}_\mathrm{loc}(\Omega)$ (i.e. $f\in L^2(\Omega)$ tout court if $k=0$ is assumed) you can drop any requirement on the boundary of $\Omega$ and on the boundary values of $u$: however the regularity result holds only locally i.e. $u\in H_\mathrm{loc}^{k+2}(\Omega)$ ([2], p. 216). There is also a counterexample to global regularity higher than $H_\mathrm{loc}^{2}(\Omega)$ involving $f\in C^0(\overline\Omega)$ ([2], pp. 246-247): precisely, for $n=2$, $\overline{\Omega}=B(0,R)=\{x\in\Bbb R^2||x|\le R<1\}$ let
$$
f=\frac{x_1^2-x_2^2}{2|x|^2}\left(\frac{4}{(-\ln|x|)^{\frac{1}{2}}}+\frac{1}{2(-\ln|x|)^{\frac{3}{2}}}\right)\in C^0(\Omega)
$$
Then the solution is such that $u\in H_\mathrm{loc}^{2}(\Omega)$ but $u\notin C^2(\Omega)$ (perhaps there is a typo in the expression of $f$ reported in the book: however, I've not checked all the calculations).
- Regarding the third boundary problem (the so called Robin problem), Mikhailov ([1], footnote *, p. 217) remarks that analysis of the regularity of solutions can be dealt as done in theorem 4 above for the solutions to the first and second boundary value problems, provided certain conditions are assumed.
[1] P. Grisvard (1985), Elliptic problems in nonsmooth domains,
Monographs and Studies in Mathematics, 24. Pitman Advanced Publishing Program. Boston-London-Melbourne: Pitman Publishing Inc., pp. XIV+410, MR0775683, Zbl 0695.35060.
[2] V. P. Mikhailov (1978), Partial differential equations, Translated from the Russian by P.C. Sinha. Revised from the 1976 Russian ed., Moscow: Mir Publishers, p. 396 MR0601389, Zbl 0388.3500.