A function is a mapping from elements of a domain set to elements of a range set (also called the "codomain"). Let's consider your example of $k(x) = \sqrt{x}$. This actually is an incomplete definition of a function; you also need to specify the domain and range. So suppose $k$ takes nonnegative real numbers to nonnegative real numbers.
Then when we take the function $g(x) = x^2+9$, we again have to specify the domain and range. So let's say $g$ takes real numbers to real numbers greater than or equal to 9.
Now consider the composition $f(x) = k(g(x))$. The equation is $\sqrt{x^2+9}$. But now the domain and range have changed a bit from the original $k$ or $g$. In particular, now the domain is all real numbers, and the range is real numbers greater than or equal to 3. So there is a subtle difference between the functions $f(x)$ and $k(x)$. It's important to keep the domain and range/codomain in mind whenever you do function composition.
Now to address your confusion regarding how we are "allowed" to set $x = x^2+9$ and write $k(x^2+9) = \sqrt{x^2+9}$. Again, think about a function as taking inputs to outputs. So when you write $k(x^2+9) = \sqrt{x^2+9}$, what you're saying is that given a number $x$, $k$ maps the number $x^2+9$ to $\sqrt{x^2+9}$. This is really just a variable substitution. There is nothing wrong with writing down $k(x^2+9)$, or $k(e^x)$; just like with $k(2)$ or $k(\pi)$, it represents passing some value into the function $k$.
Hopefully that addresses your questions, and let me know in the comments if I can clarify further!