U.S. state legislatures are critical policymaking bodies and the major pipeline of candidates to national office. Polarization in state legislatures has increased substantially in recent decades, yet we understand little about the role of elections in this process. We offer the first systematic study of state legislative candidate ideology across all election stages using a new dataset on primary- and general-election results for over 84,000 candidates, 1992-2020. To measure candidate ideology, we use machine learning to predict roll-call-based scores of ideology from millions of campaign contribution records. We find that the pool of candidates has polarized substantially in recent decades, while electoral competition has been consistently low. More-extreme candidates have enjoyed a modest advantage in contested primaries, and this advantage has doubled in the past decade. More-moderate candidates previously enjoyed an advantage in contested general elections, but this has shrunk to nearly zero in the last decade. The results indicate a shifting equilibrium in which more-extreme candidates increasingly seek office, win primaries more often, lose general elections less often, and face limited competition, driving the rise in state legislative polarization and generating a more-extreme candidate pool for congressional elections.