Suppose I have a random number generator that generates random numbers $x$ with a normal distribution
$p(x) \propto e^{-x^2}$
(modulo normalization, but lets keep it simple).
Now, out of these random numbers I'd like to generate random numbers $y$ with a slightly modified distribution:
$p(y) \propto e^{-a^2y^2}$.
I can achieve this by setting
$e^{-a^2y^2}=e^{-(ay)^2} \overset{!}{=} e^{-x^2}. \qquad (1)$
From what follows that $x=ay$ or $y=a^{-1}x$. Thus by multiplying my original numbers with $a^{-1}$ I get the desired distribution.
I am missing the logical argument for the second equal sign in equation (1). Why should I set desired probability $e^{-a^2y^2}$ equal to the probability of the random generator at hand?
Long form of angryavian's argument:
Let $Y=\frac1aX=g(X)$, with $X$ having pdf $f_X$, and $a>0$.
There is a standard way to find the pdf of Y: for any integrable function $h$,
$$E(h(Y))=\int_{-\infty}^\infty h(y) f_Y(y) \mathrm{d}y$$
But you have also
$$E(h(Y))=E(h(g(X)))=\int_{-\infty}^\infty h(g(x)) f_X(x) \mathrm{d}x=\int_{-\infty}^\infty h(x/a) f_X(x) \mathrm{d}x$$
Now do a change of variable $u=x/a$:
$$E(h(Y))=\int_{-\infty}^\infty h(y) f_Y(y) \mathrm{d}y=a\int_{-\infty}^\infty h(u) f_X(au) \mathrm{d}u$$
Since it's true for any $h$, you have $f_Y(y)=af_X(ay)$.