Should I contact a PhD student or his supervisor for potential collaboration? I found some recently published papers which are related to my research and am interested in contacting the authors for potential collaboration. However, in those papers, the first author is a Ph.D. student while the second author is his supervisor, who is a well-known professor in my field. In my field, the order of author is based on contribution, which means the Ph.D. student contributed more to the paper than his supervisor.

Hence, I don't know whether I should contact the student or his supervisor to initiate the collaboration. I can see that the advantage for contacting the student is that he should know more about the research than his supervisor. On the other hand, I also look for someone that can write a reference letter for me in the future, and the supervisor sounds better.
First, check the fine print in the paper itself.  Some journals ask the authors to designate one person as the "contact author" or "corresponding author", and distinguish that author with a notation and a mark on the author list.  If that is the case, then that is the person that you should write to.

Beyond that, since the professor is well-known in your field, know that you are unlikely to end up doing much direct collaboration with them in any case, simply because they probably already have many different projects in progress.  The student is also more likely to respond at all for the same reason.

You can't know before writing, however, whether you'd mostly likely end up working with this Ph.D. student or somebody else: if the student still has some years to go, you'd likely end up collaborating with them; if they are about to defend, they might either be "taking the project" or handing it off to another student.  So if there isn't one person designated as contact author, write to both (as ff524 suggests in the comments), and let them decide how to respond.