Why is a random variable called so despite being a function? According to my knowledge, its a function $P(X)$ which includes all the possible outcomes a random event.

IMO, the random variable X can be considered as a variable resulted from a function, and it's often being used as a variable in $P(X)$. For example, $y=mx+c$ is a function, but it can be used as a variable to $f(y)=y^2$.
