I am working on exercise involving the PDE
$\frac{1}{2}{\sigma}^2 S^2 \frac{\partial^2 P}{\partial S^2}-rP+r\frac{\partial P}{\partial S}=0$
The solution I am looking at says to assume $S^{\lambda}$ where $\lambda$ is a real number and then works from there. Can anyone explain the idea behind this assumption?
This is an educated guess based on experience. For non-linear/non-homogeneous/non-autonomous ODEs there is no unifying approach to solve such an equation in general.
Your ODE is a so called Euler equation, for which it is known that the substitution $P=S^\lambda$ "works".
Normally for such a guess, the German word "Ansatz" is used, which Wikipedia defines as: "an ansatz is an educated guess that is verified later by its results".