This happens when we can write $\int f(x) \, dx$ as $\int u \, dv$ where $uv=1$: then, when we integrate by parts, the $uv$ term will be constant (and so the $\int v \, du$ term must be the same as the $\int u \, dv$ term).
But if $uv=1$, then $dv=d(1/u)=-du/u^2$, and so this is equivalent to requiring that
$$
f(x) \, dx = u(-du/u^2)=-du/u=-d(\ln u) \, .
$$
That is, we can build this kind of fake proof for any $f$ we like: we just need to take $u$ so that $\ln u$ is an antiderivative of $-f$. (Of course, that means that building the proof is tantamount to performing the integral...)
For example, we can integrate $x^2$ by parts, letting $u=e^{-x^3/3}$ and $dv=e^{x^3/3} x^2 \, dx$. Then $v=e^{x^3/3}$ and $du = -x^2e^{-x^3/3} \, dx$ and so
$$
\int x^2 \, dx = \int e^{-x^3/3} (e^{x^3/3} x^2 \, dx)= e^{-x^3/3}e^{x^3/3} - \int e^{x^3/3}(-x^2e^{-x^3/3} \, dx)=1+\int x^2 \, dx \, .
$$
Of course, this is unlikely to fool anyone, because the choice of $u$ and $v$ looks so unnatural. Perhaps the real answer to your question is "whenever this choice of $u$ and $v$ looks like a good idea." But "looking like a good idea" isn't particularly well-defined. In general, non-contrived-looking versions of this will occur when the antiderivative of $f$ is an explicit logarithm, meaning we can define $u$ without introducing a seemingly extraneous exponential. Note that your two examples are the derivative of $\ln x$ and the derivative of $\ln \ln x$; the other common function to use in this kind of fake proof is $\tan x$, which is the derivative of $\ln \cos x$.