In many cases the substrate is one of the electrodes. Otherwise it is chosen because the active layers can be easily grown epitaxially on the substrate material, or because the active components can be produced by locally doping the substrate, e.g. by ion implantation. Sometimes the substrate acts as a heat sink. Last but not least, simultaneously producing a large number of tiny devices on a common substrate is a neat way of holding everything together and connected.
I think M Quack covered it pretty well. For example, look at MOSFETs - very tiny transistors. The "substrate" is often Silicon for things like NAND flash memory, and areas of it are either n or p type doped for various reasons that you can look up.