How is the codomain for a function defined? Or, in other words, why aren't all functions surjective? Isn't any subset of the codomain which isn't part of the image rather arbitrary?

Yes it is arbitrary, and in a sense this is exactly the problem. When we have a function we would like to be able to talk about the inverse of the function (assuming it is 1-1.) 
Consider the following: I have some function $f$ that maps $\mathbb{N} \rightarrow \mathbb{R}$ such that $$f(x) = (e^\sqrt{3.7x}+137.2)^3$$ The point here is that it is much easier to say that my codomain is $\mathbb{R}$ and my function is not surjective than to explicitly list the image of my function and say that $f$ is surjective on this subset of $\mathbb{R}$.
I know that every output will be a real number, but it is hard to say exactly which numbers I will get out of $f$ and which real numbers I can never get. To get to the point, if my function was surjective I know that I could plug any real number into $f^{-1}$. But I know it's not and I therefore have to be very careful with my inputs to $f^{-1}$, restricting my attention only to $f$'s image (otherwise the inverse is undefined.) In this case, we say that $f$ does not have the 'nice' property of surjectivity.
