Is it necessary, that the public key is a prime number in the RSA algorithm?
There is no specific reason why $e$ is required to be a prime number.  It must be relatively prime to $\phi(n)$ (otherwise we can't decrypt uniquely); however that is the only hard requirement.  Assuming that 9 is relatively prime to $\phi(n)$, there is no reason why 9 can't be used as a public exponent.

However, selecting a prime value for $e$ does have this practical advantage; for prime $e$, then the requirement that it is relatively prime to $\phi(n)$ is equivalent to the statements that $p \ne 1 \pmod{e}$ and $q \ne 1 \pmod{e}$ (where $p$ and $q$ are the prime factors of $n$). If we use the common logic of selecting $e$ first, and then $p$ and $q$, this turns into a relatively simple additional criteria when doing prime selection.