Pleiotropy is the property of genes affecting multiple functions or characters of an organism. Genes vary widely in their degree of pleiotropy, but this variation is often considered a by-product of their evolutionary history. We present a functional theory of how pleiotropy may itself evolve. We consider genes that contribute to two functions, where contributing more to one function detracts from allocation to the second function. We show that whether genes become pleiotropic or specialize on a single function depends on the nature of trade-offs as gene activities contribute to different traits and on how the functionality of these traits affects fitness. In general, when a gene product can perform well at two functions, it evolves to do so, but not when pleiotropy would greatly disrupt each function. Consequently, reduced pleiotropy should often evolve, with genes specializing on the trait that is currently more important to fitness. Even when pleiotropy does evolve, not all genes are expected to become equally pleiotropic; genes with higher levels of expression are more likely to evolve greater pleiotropy. For the case of gene duplicates, we find that perfect subfunctionalization evolves only under stringent conditions. More often, duplicates are expected to maintain a certain degree of functional redundancy, with the gene contributing more to trait functionality evolving the highest degree of pleiotropy. Gene product interactions can facilitate subfunctionalization, but whether they do so depends on the curvature of the fitness surface. Finally, we find that stochastic gene expression favors pleiotropy by selecting for robustness in fitness components.