An emerging paradigm in the field of in vivo protein biophysics is that nascent-protein behavior is a type of nonequilibrium phenomenon, where translation-elongation kinetics can be more important in determining nascent-protein behavior than the thermodynamic properties of the protein. Synonymous codon substitutions, which change the translation rate at select codon positions along a transcript, have been shown to alter cotranslational protein folding, suggesting that evolution may have shaped synonymous codon usage in the genomes of organisms in part to increase the amount of folded and functional nascent protein. Here, we develop a Monte Carlo-master-equation method that allows for the control of nascent-chain folding during translation through the rational design of mRNA sequences to guide the cotranslational folding process. We test this framework using coarse-grained molecular dynamics simulations and find it provides optimal mRNA sequences to control the simulated, cotranslational folding of a protein in a user-prescribed manner. With this approach we discover that some codon positions in a transcript can have a much greater impact on nascent-protein folding than others because they tend to be positions where the nascent chain populates states that are far from equilibrium, as well as being dependent on a complex ratio of time scales. As a consequence, different cotranslational profiles of the same protein can have different critical codon positions and different numbers of synonymous mRNA sequences that encode for them. These findings explain that there is a fundamental connection between the nonequilibrium nature of cotranslational processes, nascent-protein behavior, and synonymous codon usage.