There are a variety of factors, and the sample is too diverse to come up with a simple answer. For starters, here's a list of all the State-run universities in the USA. This answer is basically an outline, based on my impressions, and I invite others to elaborate on these points with historical documents (this answer is a wiki) or maybe even a statistical analysis if we're lucky.
1) The need for a state school. Some regions already had several private universities that could serve their population. Others (California?) did not, so the state set one up.
2) The political commitment to the University system. Some state schools (CA) are written into the state's constitution. Other's are not (PA). Some were established with land-grants.
3) In a less formal sense, some states have a strong public commitment to public education, while others value it less. The rankings of high schools has some correlation to my perception of flagship university quality.
4) As implied in the question, the total resources available to the state is an issue, though not the only one. Still, overall, larger and wealthier (and more urban) states tend to have more prestigious flagship universities.
5) And then there's randomness (as described by Chris Lively) -- all the stuff that is not a characteristic of the state per se. AKA, historical contingencies, personnel decisions, strategic decisions, and the general legacy of the University's infrastructure..
It would be interesting to see how all these factors contribute to predicting the prestige of the flagship university (a PCA or logistic regression, perhaps)-- but that analysis is outside of my expertise.