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?

Often what is important is not functions but collections of functions, especially subsets of the set of functions between two sets $X$ and $Y$, some of which will be surjective and some of which won't.  What also doesn't get emphasized a lot at the level of elementary set theory is the compositional structure of functions, e.g. a function $f : X \to Y$ can be composed with a function $g : Y \to Z$ to give a function $fg : X \to Z$.  For the purposes of studying this compositional structure (for example if $X = Y = Z$) it is generally important not to require that $f$ and $g$ be surjective or you will miss out on structure.  
For example, a simple way to define a dynamical system is just as a function $f : X \to X$.  Whether $f$ is surjective or not is an important aspect of classifying the dynamics of $f$, or in other words of classifying the behavior of the sequences $\{ x, f(x), f^2(x), f^3(x), ... \}$ for various $x$.  This sequence is not well-defined if you pretend that the domain and codomain of $f$ are different just because the range and the codomain aren't equal.
This is another way of saying that a function really consists of three pieces of data (a domain, a codomain, and the mapping from one to the other), but the reason these three pieces of data are all important is really the compositional structure.  
