The Yoneda lemma tells us that given an object X
$X$ of a category C
$\mathcal C$, the (covariant, contravariant, whatever) functor h_X : C -> Set
$h_X : \mathcal C \to \mathsf{Set}$, which sends an object Y
$Y$ to the set Hom(Y,X)
$\mathsf{Hom}(Y,X)$, can be thought of as the "same" as the object X$X$. There are many situations in which we are interested in a functor F : C -> Set
$F : \mathcal C \to \mathsf{Set}$, and we might like to know whether F
$F$ is isomorphic to h_M
$h_M$ for some object M
$M$, because that reduces the study of F
$F$ to the study of a single object M
$M$. In such a case we say that F
$F$ is represented by M
$M$. The letter M
$M$ here, suggestively, stands for "moduli".
Example: Given a group G
$G$, the functor BG' : Top -> Set
$BG' : \mathsf{Top} \to \mathsf{Set}$ is the functor which sends a topological space X
$\mathcal X$ to the set of isomorphism classes of principal G
$G$-bundles over X
$\mathcal X$. (You can also do the analogous thing for schemes.)
Example: The functor M_g' : Sch -> Set
$M_g' : \mathsf{Sch} \to \mathsf{Set}$ is the functor which sends a scheme X
$X$ to the set of isomorphism classes of flat families of genus g
$g$ curves over X
$X$.
In both of the above examples, there is no object M
$M$ for which h_M
$h_M$ is isomorphic to the functor. So this is perhaps not so nice. But, without getting into too many details, there is a natural "fix", namely we can instead consider the functor BG : Top -> Groupoid
$BG : \mathsf{Top} \to \mathsf{Groupoid}$ (resp. M_g : Sch -> Groupoid
$M_g : \mathsf{Sch} \to \mathsf{Groupoid}$) which sends a topological space (resp. a scheme) to the groupoid of G
$G$-bundles (resp. flat families of genus g
$g$ curves). This groupoid has objects G
$G$-bundles and morphisms isomorphisms of G
$G$-bundles (resp. the obvious analogous thing). The original set-valued functor is just the composition of this functor with the functor Groupoid
$\mathsf{Groupoid}$ to Set
$\mathsf{Set}$ which takes a groupoid and returns the set of isomorphism classes of objects in the groupoid.
Anyway, despite the fact that the set-valued functors are not so "geometric", since they are not represented by a "geometric" object (topological space and scheme, respectively), the groupoid-valued functors are more "geometric". In the case of M_g
$M_g$, the "geometric" structure we get is that of a "Deligne-Mumford stack", which essentially means that we can for practical purposes pretend that it is represented by a scheme with only some slightly "weird" properties. In the case of BG
$BG$ (the topological one) you can take a "geometric realization" and recover the classifying space BG
$BG$ that we know and love.
Another very important reason for studying groupoids and another very important class of groupoids comes from, as others have already mentioned, group actions. When a group acts on a manifold or a variety, the naive quotient may be badly behaved, for example it may no longer be a manifold (e.g. it might not be smooth, or it might not be Hausdorff) or respectively a variety (or it may not even be clear how to take the quotient at all!), which makes it harder to study geometric properties of the alleged "quotient". However, the groupoid viewpoint allows us to get a better handle on the quotient and its geometry. More precisely, if G
$G$ is a group acting on a space (manifold, scheme, variety, whatever) X
$X$, then the "correct" quotient is actually the functor X/G : C -> Groupoid
$X/G : \mathcal C \to \mathsf{Groupoid}$ (where C
$\mathcal C$ is the category of manifolds, schemes, whatever) which sends an object Y
$Y$ to the groupoid of pairs (G
$G$-bundles E
$E$ over Y
$Y$, G
$G$-equivariant morphism from the total space of E
$E$ to X
$X$). The functor BG
$BG$ is a special case of this; it's pt/G
$\mathrm{pt}/G$.