What are the benefits of PhD students working on projects where they won't be first-author?
In disciplines* where the PhD thesis consists of a set of published articles, the PhD usually - but not always - must be composed of first-author papers. Yet there are many reasons why it might be beneficial to be involved in other projects as well, so long as one is also making reasonable progress toward the dissertation. 

Perhaps the two most important reasons are:


Training. Early on in graduate school, it may be valuable to simply have the experience of going through every stage of a research project from conception to publication, without having to be in charge every step of the way. Often a first of second year student will be involved in a research project on which a more senior student or postdoc is first author. 
Portfolio-building. For most students the goal is not merely to finish the dissertation, but to do so in a way that positions the student for future success. It may be preferable to graduate with 3 first-author and 4 mid-author papers instead of 4 first-author papers, for example.


Additional reasons include


Research assistantship duties. If one is being paid on an RAship, this often contributes substantially to published research that may not be directly relevant to the dissertation.
Reciprocity. Sometimes students collaborate on a series of papers and alternate first authorships as they go. 
Too good a thing to pass up. Sometimes the lab hits on something so cool that one would be a fool not to be part of it, whatever the authorship position.
Networking. By establishing collaborations with researchers beyond one's home lab and institution, one builds up one's professional network. 


This is only a partial list, of course, but it should provide a sense of some of the reasons that graduate students should not shy away from projects that will lead to mid-author publications. 


Authorship order does not matter in all disciplines. In economics and some subfields of computer science, for example, authorship is alphabetical by convention. Clearly this distinction does not matter in those fields.


[ Edited to include suggestions from the comments and other answers. ]