A proof which results in Gamma (or Erlang) distribution-From Karlin & Taylor's "A First Course in Stochastic Processes" The random variables X and Y have the following properties: X is positive, i.e., $P\{X > 0\} = 1$, with continuous density function $f_X(x)$, and $Y\mid X$ has a uniform distribution on $\{0,X\}$. Prove: If $Y$ and $X-Y$ are independently distributed, then $f_X(x) = a^2xe^{-ax},\:x>0,\:a>0.$
Progress: $Z := X-Y,\:Z\perp Y\:(\text{given}) \Rightarrow \psi_X(s) = \psi_Z(s)\psi_Y(s)\:  (\text{since }X = Z + Y)$
$$f_{Y\mid X}(y\mid x) = \frac{1}{2}[\delta(y) + \delta(y-x)]\:\Rightarrow f_{X,Y}(x,y) = f(x)f_{Y\mid X}(y\mid x)$$
$$f_Y(y) = \frac{1}{2}[\delta(y) + f(y)]$$
$$Z := X-Y\geq 0,\: f_Z(z) = \int_0^\infty \frac{1}{2}f(z+y)[\delta(y) + \delta(y-(z+y))]\,dy$$
Since these are non-negative random variables, I decided to use Laplace transform and try to solve $\psi_X(s) = \psi_Z(s)\psi_Y(s)$ for $\psi_X(s)$ which is the Laplace transform of $f(x)$.
 A: Let $f$ be the density of $X$. The joint density of $(X,Y)$ is
$$
f_{X,Y}(x,y)=f_{Y|X}(y|x)f(x) =
\begin{cases}
\frac1xf(x), &\text{if $x>0$ and $0<y<x$}\\
0, &\text{otherwise.}
\end{cases}
$$
Put $Z:=X-Y$. Apply the Jacobian formula to find the joint density of $(Z,Y)$:
$$
f_{Z,Y}(z,y)=f_{X,Y}(z+y,y)=
\begin{cases}
\frac1{z+y}f(z+y), &\text{if $z>0$ and $y>0$,}\\
0, &\text{otherwise.}
\end{cases}\tag1
$$
Since $Z$ and $Y$ are independent, the joint density in (1) factors into the product of two univariate densities, say $f_{Z,Y}(z,y)=:A(z)B(y)$.
Letting 
$y\to0$ for fixed $z>0$
and letting 
$z\to0$ for fixed $y>0$, we find
$$
A(z)={f(z)\over cz}\;\text{and}\;B(y)={f(y)\over cy}\;,
$$
where $\displaystyle c=\int{f(t)\over t}\,dt$ is a normalizing constant. Put $\displaystyle g(t):={f(t)\over c^2t}$, so that
$$
g(z+y)={f(z+y)\over c^2(z+y)}={f_{Z,Y}(z,y)\over c^2} = {f(z)\over c^2z}{f(y)\over c^2y} = g(z)g(y)\quad\text{for all $z>0$, $y>0$.}
$$
Since $g$ is continuous and not identically zero, it follows that $g(t) = e^{-at}$ for some constant $a$, and therefore $f(t)=c^2te^{-at}$. Since $f$ is a density, we must have $a>0$ and $c^2=a^2$.
