Why is it important to have a discrepancy between image and codomain?
Solution 1:
The reason for this discrepancy is that for many functions it's not particularly important what its image is, while at the same time it would be tricky to figure this out. The codomain however is easy, it describes the type of value one can get. Is it a real number, a complex number, a fraction?
For example, $$f(x)=e^{x\bar{x}}+\frac{7}{3^{x\bar{x}+4}}$$
It's true that $f:\mathbb{C}\rightarrow\mathbb{C}$, but in fact $f:\mathbb{C}\rightarrow \mathbb{R}$. Hence the codomain gives useful information, but the image is difficult to determine.
Solution 2:
Codomain and Image of a function are two completely different concepts. The codomain of a function often has a structure, like being a topological space or something like this. It will be very inconvenient to put all that structure in the image, which is only a set, and often not such a nice one. Taking your example, one could say that for $x \to \infty$ the function converges to $0$; when you just look at the image of the function it can't converge to $0$ at all because $0$ is not in the image. And definitions like the pointwise addition of two functions will be much broader as it is sometimes hard to say what is the image of the sum of two functions.
Solution 3:
You cannot speak about surjectivity (that is, whether it is onto) otherwise. If we would define the codomain of every function to be its image, then every function would be surjective.
Solution 4:
What is a function? Informally, it is a process, or an assignment, from an input set to an output set. It is not just the process or assignment that forms a function, but specifying the input and output is part of what it is. Formally, a function is a triple $(A,B,f)$ where $A,B$ are sets and $f\subseteq A\times B$ is a subset of the cartesian product, i.e., a relation from $A$ $to$ $B$. If instead one wanted to view the function $(A,B,f)$ as equivalent to $(A,Im(f),f)$ then one needs to add a condition to an otherwise very clean definition. So, to force the codomain to be the range actually burdens the definition rather than simplify things. That is one reason not to force such things.
Another reason is so that one has no problems talking about composition when it's obvious one should be able to talk about composition (so actually this is a category theoretic reasoning). Suppose that $f:A\to B$ and $g:B\to C$. If I want to know if the composition $g\circ f$ exists I don't care what the actual range of the functions is. Just a glance as the domain of $g$ and the (ta ta ta taaaaaa) codomain of $f$. In other words, if the input type of $g$ matches the output type of $f$, then the composition is defined.
If we insisted that codomain=range, then the condition above will have to be replaced by "the range of $f$ is contained in the domain of $g$". And now I'll get into a bit of technical lingo from category theory. The resulting category from forcing codomain=range will be the category $Set_{Surj}$ of sets and surjections. It's a perfectly legit category, but it has far fewer nice properties when compared to $Set$, the category of sets and all functions. For instance, the empty set is characterized in $Set$ as an initial object (i.e., there is precisely one function from it to any other given set) and is dual to singletons, which are terminal. This is no longer the case in $Set_{Surj}$. The disjoint union of two (or more) sets is an example of a categorical product in $Set$, and is dual to the cartesian product. Disjoint unions are no longer coproducts in $Set_{Surj}$. Many other of the nice properties of $Set$ are lost if passing to $Set_{Surj}$.
In particular, many very convenient injections will no longer be allowed if we require all functions to be surjective. For instance, it is very convenient to be able to speak of the functions $f_y:\mathbb R \to \mathbb R^2$, given by $f(x)=(x,y)$, or various curves in the plane being parametrized by some function $\gamma:[a,b]\to \mathbb R^2$.
Solution 5:
The most obvious reason is just that it's impractical. The image may be difficult to write down. Say for example we consider $f(x) = \frac{x^3}{1+e^x}$.
In order to define the image I have to work out the maximum, which involves solving $f'(x) = 0$. But I can't differentiate $f(x)$ until I've defined it. So I need to define a co-domain before the image makes sense.
The other good reason is that we're often interested in sets of functions. So I might talk about $C^1(\mathbb R)$ which is the set of functions $\mathbb R\to\mathbb R$ with a continuous first derivative.
To construct the set I'm interested in we need to talk about the co-domain. My function $f\in C^1(\mathbb R)$ but it wouldn't be if I had to define $C^1(\mathbb R)$ as functions whose image was $\mathbb R$.
So although the image can be important the co-domain is necessary too.