I have the following situation in mind: consider two people A and B, who are roughly "equally good" in their field and do their bachelors in the same university - a small, not widely known insitution. Then student A stays there for his/her Master's, while student B chooses to do his Master's in a more prestigious place.
At the end, they both apply to a PhD at some competitive place. Coming from a "modest" university, where he easily stands high above the average, student A is highly regarded by his/her professors and so manages to get very good recommendation letters. On the other hand, student B studied in a place where students of his level are more common, and so he doesn't impress his professors as much, and they don't speak so highly about him in recommendation letters.
Do you think that scenarios like this could actually make student A seem a better candidate than student B in practice? In this sense, could studying at a good university hurt your career in the long run? Or would the prestige of the university where student B studied (as well as possibly the prestige of the professors who wrote recommendation letters about him) make up for the more modest recommendation letters?