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.
A brand new BGA chip has hundreds of solder balls underneath, acting like the pins on a DIP package. When the component is reworked, the balls are damaged and need to be replaced. After removing the old balls, the stencil can be used to apply solder paste and new solder balls to the chip. Once the chip is reballed, it can be reflowed onto the board.
https://youtu.be/Iu0pd6OsNF4?t=235 https://youtu.be/2bGb5AOwp44?t=109