As alluded to in a comment of @PietroMajer the reason that one can't solve in the space of compactly supported functions is somewhat subtle (and in particular, I think the other answers are not complete). Basically, for a solution of $\Delta_g f=g$ to exist with both $f,g\in C^\infty_c(M)$ one has to have that $g$ is $L^2$ orthogonal to every harmonic function. There are, in general, a plethora of these when the ambient space is non-compact and these impose serious restrictions on the allowed $g$. Just to give a concrete example in $\mathbb{R}^2$. Let $\phi\geq 0$ be a non-negative compactly supported function with $\phi=1$ on $B_1$. Set $g=(x^2-y^2)\phi$. Now suppose one had a compactly supported solution $f$ to $\Delta f=g$. Integration by parts gives \begin{align*} 0&=\int_{\mathbb{R}^2} f \Delta (x^2-y^2) \\ &=\int_{\mathbb{R}^2} (x^2-y^2) \Delta f \\ &= \int_{\mathbb{R}^2} \phi (x^2-y^2)^2 >0 \end{align*} This is a contradiction so there can be no such solution. It might also be illustrative to see what happens in $\mathbb{R}$. You can see that to solve $f''=g$ for $f$ and $g$ compactly supported as this is just an integration and the conditions are quite explicit.