A functor $F$ is defined to be a mapping from category $\mathcal{C}$ to $\mathcal{D}$ such that:
(1) $F(f\circ_{\mathcal{C}} g)=F(f)\circ_{\mathcal{D}} F(g)$ (say, for a covariant functor).
(2) $F(id_{A})=id_{F(A)}$
Question: why is (2) necesssary?
Here is an attempt to show that (1) implies (2), I would appreciate to be told where it fails:
Take any $f\in hom_{\mathcal{C}}(A,B)$, $g\in hom_{\mathcal{C}}(B,A)$ Then $$ F(f)\circ F(id_{A}) \stackrel{(1)}{=} F(f\circ id_A) = F(f) $$ and $$ F(id_A) \circ F(g) \stackrel{(1)}{=} F(id_A \circ g) = F(g) $$
So that $F(id_A)$ satisfies the axioms of an identity (assuming that $F$ is surjective, though I'm not sure what that means for functors), and since identities are unique (an easy lemma) then $id_{F(A)}=F(id_A)$.
The two problems, as noted are:
(a) $F$ might not be surjective.
(b) $hom_{\mathcal{C}}(A,B)$ or $hom_{\mathcal{C}}(B,A)$ might be empty.
Can anyone explain more about this? Show an non-stupid example where something would fail to be a functor because of this?
Consider the following counterexample.
Let $\mathcal{C}$ be the category with one object $C$ and one morphism $\mathrm{id}_C$. Let $\mathcal{D}$ be the category with one object $D$ and two morphisms $\mathrm{id}_D : D \to D$ and $f : D \to D$, where composition is defined by $f \circ f = f$.
Define $F : \mathcal{C} \to \mathcal{D}$ by $$F(C)=D \qquad \text{and} \qquad F(\mathrm{id}_C)=f$$ Then $F$ satisfies all the requirements of being a functor, except for the requirement that $F(\mathrm{id}_C)=\mathrm{id}_{D}$, since $F(\mathrm{id}_C)=f\ne\mathrm{id}_D$.
Added: As per your question in the comments, here's an example where $F$ is surjective on morphisms: take $\mathcal{C}$ to be a category with two objects $C_1$ and $C_2$ and only identity morphisms, take $\mathcal{D}$ as before, define $F(C_1)=F(C_2)=D$, $F(\mathrm{id}_{C_1})=f$ and $F(\mathrm{id}_{C_2})=\mathrm{id}_D$.