Jingxuan
Correct and minimalist proof of necessity. Obviously $u_{xx}=y^2$, $u_{yy}=-x^2$ does not satisfy and solution does not exist.
To prove that this compatibility condition $f_{yy}=g_{xx}$ is sufficient (under additional assumption that domain is convex, you can figure out generalization) solve $u_{xx}=f$, $u(0,y)=\phi(y)$, $u_x(0,y)=\psi(y)$ where $\phi$, $\psi$ so far are unknown and will be chosen later. Such $u$ obviously exist for any $\phi$, $\psi$.
What about $v:=u_{yy}-g=0$? Obviously $v_{xx}=0$ and we need to satisfy $v(0,y)=0$, $v_x(0,y)=0$, which are, in fact, $\phi '' -g(0,y)=0$, $\psi ''- g_x(0,y)=0$, and we can satisfy these two equations. Four arbitrary constants $C_1=\phi(0)$, $C_2=\phi'(0)$, $C_3=\psi(0)$ and $C_4=\psi'(0)$ appear.