They assign points.
So many points for your STEP scores.
So many for clinical grades.
So many for your interviews.
Etc.
Then there's the "fudge points" like how much did the other residents like you, did one of the most respected attendings go to bat for you, etc
Add up the points--easy peasy.
The reality is PDs can never know everything about everyone in detail. "The Program" may rank you #4 instead of #5, but an all-knowing PD might have preferred it the other way around. But no PD is all-knowing, so they trust the opinions of their interviewers and the process they've developed.
PDs who obsess over who to rank #24 vs #25, and so on, will never get anything done. So they likely do a "good enough" job and move on with their lives. Presumably at worst they do the same thing the average med student does with our rank list. We obsess, then rank, re-rank, then final rank, then move on. PDs can do that too, but they have a full-time job to do (and maybe a family), so it's unlikely they have the time to be as neurotic as a 4th year med student on an elective rotation.
Small programs that interview just 10-15 people for 2 spots or whatever (ie, fellowship programs) are an entirely different ballgame, and ranking is far more, if not entirely dependent, on what the PD thinks.