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?

This is something that trips people up the more they dwell on it.  And depending on how you like to think about mathematical objects, you have different preferred answers.  
More often than not, I tend to think of a function as consisting of three things: a domain $A$, a range $B$ and a subset $S$ of $A \times B$ which satisfies this condition, that for any $a \in A$ there is a unique $b \in B$ such that $(a,b) \in S$.  To be precise, a "function" $f$ is a triple $(A,B,S)$ where $S \subset A\times B$ satisfies the above criterion. We say $f : A \to B$ and $f(a) = b$ provided $(a,b) \in S$. 
In the above formalism, you can't describe a function without specifying the domain and range before hand. To be specific, here are two different ways of specifying the function that in a calculus class would just be called $x^2$:  $f=(\mathbb R, \mathbb R, \{(x,x^2) : x \in \mathbb R\})$.   $g=(\mathbb R, [0,\infty), \{(x,x^2) : x \in \mathbb R\})$.  So in this formalism, $f$ is not an onto function, while $g$ is an onto function.  Although $f(x)=g(x)$ for all $x$ in the domain of $f$ and $g$, $f \neq g$ since they have different ranges. 
If you don't use a formalism like the above, yes, the range (or co-domain as you say) is just any arbitrary set containing the image.  Frequently this is taken care of by considering the range to be a typical "universal" set. In a standard calculus course what happens is people never really mention the range, they only talk about the image. 
