You can buy spacers that fit under a component such as an LED (a tube or something similar that the LED leads go through). Spacers are also available for other components, see companies such as Bivar and a number of Asian companies.

There are versions of the above that are made with a material that is designed to withstand wave soldering but dissolve in the cleaning process. Bivar has some such wash-away spacers and there are other suppliers as well.
However, my preferred method is to use a machined fixture or jig to hold the component and PCB in alignment while soldering is taking place. Sometimes, for hand soldering especially, you can use a 3D printed fixture or jig. This method can be more accurate than the use of spacers.
For example, to hold 3mm through-hole LEDs in specific alignment a certain distance above the PCB, or an LED display so that it is spaced a bit off the PCB to be closer to a window.
If the distance is too great or the leads too short, you can just use a sub-PCB and connect the two with connectors or flat cable or make the whole PCB using a rigid-flex construction, snap off the part that has to be at a different level and mount it with hardware etc. Photo from here. Such rigid-flex PCBs tend to be quite pricey. You can also get into different planes with the flex, but keep in mind the flex is a developable surface so it the rigid parts cannot be oriented arbitrarily without folds in the flex (as a connection made with a wire harness could be).
