You screen print solder paste through the stencil, onto the board.
You then push the components onto the paste.
In the past you didn't have to be too precise, because surface tension of the solder as it flowed would pull it onto its pad, and would align the component correctly.
For production you'd have camera aligned tables.
Re rework you have little tiny masks.
Here's a bit of video: https://www.youtube.com/watch?v=LaqeLrLxYOg (Screen printing starts at about 1:40)
I used to operate a screen printer, pick and place machine, and reflow oven. But that was 12 years ago. The machines are amazing now.