In defining sheaf cohomology (say in Hartshorne), a common approach seems to be defining the cohomology functors as derived functors. Is there any conceptual reason for injective resolution to come into play? It is very confusing and awkward to me that why taking injective stuff into consideration would allow you to "extend" a left exact functor.
Since everybody else is throwing derived categories at you, let me take another approach and give a more lowbrow explanation of how you might have come up with the idea of using injectives. I'll take for granted that you want to associate to each object (sheaf) $F$ a bunch of abelian groups $H^i(F)$ with $H^0(F)=\Gamma(F)$, and that you want a short exact sequence of objects to yield a long exact sequence in cohomology. I also want one more assumption, which I hope you find reasonable: if $F$ is an object such that for any short exact sequence $0\to F\to G\to H\to 0$ the sequence $0\to \Gamma(F)\to \Gamma(G)\to \Gamma(H)\to 0$ is exact, then $H^{i}(F)=0$ for $i>0$. This roughly says that $H^{i}$ is zero unless it's forced to be nonzero by a long exact sequence (you might be able to run this argument only using this for $i=1$, but I'm not sure). Note that this implies that injective objects have trivial $H^{i}$ since any short exact sequence with $F$ injective splits. Now suppose I come across an object $F$ that I'd like to compute the cohomology of. I already know that $H^{0}(F)=\Gamma(F)$, but how can I compute any higher cohomology groups? I can embed $F$ into an injective object $I^{0}$, giving me the exact sequence $0\to F\to I^{0}\to K^{1}\to 0$. The long exact sequence in cohomology gives me the exact sequence $$0\to \Gamma(F)\to \Gamma(I^{0})\to \Gamma(K^{1})\to H^{1}(F)\to 0 = H^1(I^{0})$$ That's pretty good; it tells us that $H^{1}(F)= \Gamma(K^{1})/\mathrm{im}(\Gamma(I^{0}))$, so we've computed $H^{1}(F)$ using only global sections of some other sheaves. We'll come back to this, but let's make some other observations first. The other thing you learn from the long exact sequence associated to the short exact sequence $0\to F\to I^{0}\to K^{1}\to 0$ is that for $i>0$, you have $$H^{i}(I^{0}) = 0\to H^{i}(K^{1})\to H^{i+1}(F)\to 0 = H^{i+1}(I^{0})$$ This is great! It tells you that $H^{i+1}(F)=H^{i}(K^{1})$. So if you've already figured out how to compute $i$th cohomology groups, you can compute $(i+1)$th cohomology groups! So we can proceed by induction to calculate all the cohomology groups of $F$. Concretely, to compute $H^{2}(F)$, you'd have to compute $H^{1}(K^{1})$. How do you do that? You choose an embedding into an injective object $I^{1}$ and consider the long exact sequence associated to the short exact sequence $0\to K^{1}\to I^{1}\to K^{2}\to 0$ and repeat the argument in the third paragraph. Notice that when you proceed inductively, you construct the injective resolution $$0\to F\to I^{0}\to I^{1}\to I^{2}\to\cdots$$ so that the cokernel of the map $I^{i1}\to I^{i}$ (which is equal to the kernel of the map $I^{i}\to I^{i+1}$) is $K^{i}$. If you like, you can define $K^{0}=F$. Now by induction you get that $$H^{i}(F) = H^{i1}(K^{1}) = H^{i2}(K^{2}) = \cdots = H^{1}(K^{i1}) = \Gamma(K^{i})/\mathrm{im}(\Gamma(I^{i1})).$$ Since $\Gamma$ is left exact and the sequence $0\to K^{i}\to I^{i}\to I^{i+1}$ is exact, you have that $\Gamma(K^{i})$ is equal to the kernel of the map $\Gamma(I^{i})\to \Gamma(I^{i+1})$. That is, we've shown that $$H^{i}(F) = \ker[\Gamma(I^{i})\to \Gamma(I^{i+1})]/\mathrm{im}[\Gamma(I^{i1})\to \Gamma(I^{i})].$$ Whew! That was kind of long, but we've shown that if you make a few reasonable assumptions, some easy observations, and then follow your nose, you come up with injective resolutions as a way to compute cohomology. 


Even though I'm far from a historian, it seems to me the initial reason for considering injectives is prior to derived categories; but comes later than the task of extending left exact functors. For the latter, in particular, there are apparently many ways of doing it. But: injective resolutions are almost ideal for comparing different definitions of cohomology. It is important to note that cohomology was around before injective resolutions, appropriate to different situations, and then the question came up of comparing several of them when they all made sense. As a concrete example, you might consider Cech and De Rham cohomology on a smooth manifold, both with real coefficients. It's also obvious that cohomology was not initially thought of in terms of the failure of exactness, which, in any case, can be good or bad depending on the situation. Typically, you have two complexes A and O with rather different constitutions. How do we then compare their cohomology? The standard method is to find a third one C that admits natural maps A>C and O>C. Then we proceed to show that both of these induce isomorphisms on cohomology. A very basic form of this argument occurs even when showing that the cohomology computed using triangulations is independent of the triangulation. There, C is the complex associated to a common refinement. Even in other situations, it makes sense to consider C as a 'common refinement' of some sort. The point then, is that an injective complex gives an ultimate common refinement in a wide variety of situations. This is because injectives, by their very definition, receive maps (more precisely, map extensions) very easily, so that you don't need to cook up a separate C for each pair of A and O. Once the injective definition is around, the different comparisons can be made in one fell stroke with the theorem that all acyclic resolutions compute the same cohomology as the injective one. Of course, `acyclicity' here can only be defined in terms of the fixed definition using injectives, and checking for it can be tricky and situationdependent. For example, checking that the Cech resolution is acyclic on a variety requires that the covering consist of affines, and then knowledge of some property of affines. Checking that the smooth differential forms on a manifold form an acyclic requires some technicalities on partitions of unity and extensions of Cinfinity functions, and so on. (Of course such verification processes are routine, once you're used to them. But whenever they are examined afresh, they always strike me as quite technical in interesting ways.) In the end, however, it's clear that this approach brings considerable conceptual unity to the ubiquitous problem of comparing cohomology. It's my best guess at the real initial motivation behind the definition. You might even say that the definition of an injective object incarnates purely wishful thinking with regard to the problem of comparisons. What could be more naive than thinking there is one thing that frees you at once from all future specific consideration of C? The deep insight is that objects realizing such wishful thinking do exist often enough in nature. If I may add a bit of philosophical reflection, the definition of injectives illustrates quite well the sense of childlike innocence that Grothendieck regarded as fundamental to his mathematical nature. Several people have commented on the meaning of Grothendieck's selfevaluation, especially in view of the apparent sophistication of the resultant technology. It is interesting to identify the precise mathematical locus of such innocence, if only to gain some sense of when innocence is likely to yield fruit. 


This is an interesting discussion to someone raised in the 60's. It illustrates how lack of motivation creeps into books unnoticed. Back when Hartshorne was being written everyone was steeped in the then standard derived functor formalism of Cartan Eilenberg and Grothendieck, axiomatizing constructions of cohomology via complexes. So the pattern of this formalism explained so nicely by Anton and Andrew above was taken for granted. As the subject evolved, it was understood that acyclic resolutions could replace the more categorically natural injective ones. This is the gist of Evan's answer. Perhaps also there is a tradition in mathematics books of giving definitions without historical background. I have always had difficulty with any unmotivated definitions, such as abstract "residues" and modern Riemann Roch theorems, so I keep stressing to my students the value of learning the original version of Riemann, even if their goal is to understand cohomological and arithmetic versions. Anyway, excellent question. 


Here is a funny aspect of the story: When learning (co)homology one usually encounters first projective resolutions, projective objects are better to imagine in most people's opinion. But in sheaf categories there tend to be few projectives for two reasons: In usual cohomology for modules, the projectivity is a requirement on the module structure only; set theoretically the map required in the definition of "projective" always exists. This requirement on module structure has of course to be met for sheaves of modules as well. But secondly, even if you drop the requirement to be a homomorphism the map of sheaves does not need to exist: By definition of "projective" any epimorphism into a projective object has a section. For sets this is the statement of the Axiom of Choice ("every set is projective"). But in a sheaf category (which is a topos) the internal logic is in general intuitionistic, in particular the axiom of choice need not be valid and one can fail to find the section already on the level of sheaves of sets, even before looking for sections that are homomorphisms... 


In my opinion, all answers go a little too far. In this (nontopological!) setting I think about this as follows: The aim is to analyze the lack of rightexactness of a leftexact functor $\Gamma:C \rightarrow D$ between abelian categories. One functorial notion that captures this inexactness is a deltafunctor $H = \lbrace H^n, n \in \mathbb{N}$ with $H^0 = \Gamma$. This is what I call a cohomology theory for $\Gamma$. Now, there may exist a lot of them, and so it makes sense to look for universal cohomology theories for $\Gamma$, where universal means, that given any delta functor $K = \lbrace K^n, n \in \mathbb{N} \rbrace$ (not necessarily with $K^0 = \Gamma$ !) and a morphism $f^0:H^0 \rightarrow K^0$ in degree zero, then there exists a unique extension of $f^0$ to a morphism $f:H \rightarrow K$ of deltafunctors. Up to canonical isomorphism there exists only one universal cohomology theory for $\Gamma$ which is then called the right derivative of $\Gamma$. The question is of course if such a universal cohomology theory for $\Gamma$ exists. And here it comes: If the category $C$ has enough injectives, then $\Gamma$ has a right derivative which can be computed by injective resolutions. (You can confer Lang's Algebra book for all the above notions, it's actually pretty nice). The universality condition forces a strong connection between $\Gamma$ and $H$. This allows you for example to extend constructions in degree 0 to arbitrary degree. An example from group cohomology: Let U be a subgroup of a group G and let $g \in G$. Then conjugation is an isomorphism of functors $()^U \rightarrow ()^{gUg^{1}}$, where $()^U$ is the Uinvariant functor on Gmodules. Now, $H^n(U,)$ is a universal cohomology theory for $()^U$ and $H^n(gUg^{1},)$ is a universal cohomology theory for $()^{gUg^{1}}$. Hence, the exists a unique isomorphism of deltafunctors $H^n(U,) \rightarrow H^n(gUg^{1},)$ and in this way we have extended the conjugation to all cohomology groups. This is very inexplicit of course, but this is a powerful property for more advanced constructions. And verifying each time that constructions are compatible with the deltas is not a nice job (normally people simply say, it works). In Lang's book "Topics in the Cohomology of Groups" you will find a lot more of such arguments. If you now want to get rid of all choices, you can move to the derived category. Hope this helps. 


One conceptual reason is, in technical terms, that "the derived category of (boundedbelow) complexes is isomorphic to the category of (boundedbelow) injective complexes." In less fancy language: First, when working with a single sheaf A, we can make it into a complex A^{•} with one A and everything else 0: ...→0→A→0→0→0→.... Then an "injective resolution" of A is really a complex of injectives I^{•} with a quasiisomorphism A^{•}→I^{•} (a map of complexes which induces an isomorphism on cohomology). Now, say A^{•} and B^{•} are any (bounded below) complexes of sheaves which have the same (cochain) cohomology. There may not be a map from one to the other giving rise to the isomorphism of their cohomologies (kernels mod image), i.e. a quasiisomorphism (qis). However, you can find complexes of injectives I^{•} and J^{•}, and maps a: A^{•} → I^{•}, b: B^{•} → J^{•}, and f: I^{•} → J^{•} such that a,b are qis, and f is a homotopy equivalence (in particular a qis). So, "as far as cohomology is concerned", you can replace A^{•} by I^{•} and B^{•} by J^{•}. The "big picture" reason for this is that injectives are "flexible" in terms of extending maps into them (that's how they're defined), which is what allows the construction of the maps in the previous paragraph, and having maps between things is good, because maps transform nicely under the application of functors. 


If you're willing to take for granted that (boundedbelow) chain complexes and quasiisomorphisms are good things to study, then left exact functors have the defect that they do not preserve quasiisomorphisms between chain complexes. Derived functors are a way to correct this defect. The idea is that left exact functors do preserve quasiisomorphisms between complexes of injective modules, and every complex is quasiisomorphic to a complex of injectives. So whenever we want to apply a left exact functor to a complex, we should first replace the complex by a quasiisomorphic complex of injectivesit doesn't matter which replacement we pickand then apply our functor. This process goes by some name like the total right derived functor. In summary, derived functors are a way to force functors to preserve quasiisomorphisms of chain complexes. Often in homological algebra we start with a single object M rather than a complex, view it as a complex concentrated in degree 0, apply the right derived functor of F, and then take the ith cohomology group of the resulting complexwe write this as RF^{i}(M). There is a massive generalization of these ideas due to Quillenthe theory of model categories. 


The reasons injective (and dually, projective) resolutions are important in the construction of derived functor cohomology are primarily technical in nature. You can think of an injective resolution as a "nice" replacement for an object (or more generally, for a chain complex) in the homotopy category of chain complexes in the same way that we think of a CW complex as a "nice" homotopical replacement for an arbitrary topological space. A very important feature is that these replacements are functorial in the homotopy category. In other words, the resolutions are unique up to chain homotopy equivalence, and given a map between two objects, this map extends to a map between their injective resolutions uniquely (again up to chain homotopy). However, once you actually show the existence of a good notion of derived functor, you can actually use more broad classes of resolutions for computations. It's generally fairly impractical to take injective or projective resolutions. Instead of injective sheaves, one can take resolutions of acyclic objects, which are objects that themselves have no higher cohomology. There are various classes of acyclic sheaves that are often used in various contexts, such as soft sheaves, flasque (or flabby) sheaves, soft sheaves, and fine sheaves. Finding some sort of acyclic resolution is often much easier than finding an injective resolution, so understanding when various types of sheaves are acyclic is very useful. 

