A substantial factor were white primaries during the defining civil right struggles and the case law that followed from that. From a law paper on the topic "Developments in the State Regulation of Major and
Minor Political Parties" (which is 74-pages long, by the way):
If political parties were truly private organizations, they could exclude whomever they wished from political participation—a result that would conflict with the "White Primary Cases" in which the Court protected racial minorities'
right to participate in party primaries.
[in footnote] Cf. Gray v. Sanders, 372 U.S. 368 (1963) (finding state action when the state enforces exclusion of voters); Terry v. Adams, 345 U.S. 461, 469-70 (1953) (holding that the use of a discriminatory preprimary election administered by a private association, which determined the primary winner, constituted state action under the Fifteenth Amendment); Smith v. Allwright, 321 U.S. 649 (1944) (determining that political party's exclusion of African-American voters in primary constitutes state action); United States v. Classic, 313 U.S. 299 (1941) (holding that Congress can regulate fraud in primary elections); Nixon v. Condon, 286 U.S. 73 (1932) (finding that party's exclusion of black voters when authorized to determine voter qualifications constitutes state action).
And from Wikipedia's United States v. Classic:
Many observers assumed that the court had already ruled in Newberry v. United States, that primary elections could not be regulated under the powers granted to Congress under Article I, Sec. 4 of the Constitution. But writing for the majority, Justice Harlan Fiske Stone argued that the Newberry court had been deeply divided on the issue and no majority had ruled one way or the other. Utilizing the reasoning by Chief Justice Edward Douglass White and Justice Mahlon Pitney in their concurrent opinions in Newberry, Stone argued that the Constitution's protection of the right to vote cannot be effectively exercised without reaching to primary elections and/or political party nominating procedures.
Though broadly noting that the constitutional right to vote extends to a party primary even when it "sometimes or never determines the ultimate choice of the representative," the Court offered no standard for determining whether a primary "was made an integral part of the election machinery." However, in Morse v. Republican Party of Virginia, the Court clarified that this extends to virtually all primaries, noting that "Virginia, like most States, has effectively divided its election into two stages, the first consisting of the selection of party candidates and the second being the general election."
So basically the Supreme Court decided that there can be no free elections in the US without free primaries. Morse v. Republican Party of Virginia, (517 U.S. 186, 205-07 (1996)), which cemented/clarified this is a relatively recent decision, surprisingly.
However, the Fifteenth Amendment is relatively narrow. It
prohibits the federal and state governments from denying a citizen the right to vote based on that citizen's "race, color, or previous condition of servitude".
So based on it the government(s) don't get to regulate everything relating to primaries or nominations. In particular, it doesn't say who can or cannot be nominated in a primary. And the case law in this respect is much, much less straightforward (one reason why that law review is so long). I'm not going to get into the details here... but I will mention one case that limited the state's right to dictate every minute detail of how primaries have to be organized: Republican Party v. Faulkner County; without getting into the gritty case details, the principles derived in this case were (quoting from the law review again):
Faulkner is significant because the Eighth Circuit used associational
rights as a substantive limit on the state's ability to dictate a
party's nominating procedures. A state can violate a political
party's associational rights if the state enacts a primary election system
that unduly burdens the party's association with its members. Moreover,
the court reached this conclusion by considering the actual impact
of the nominating procedure on the party's campaign activities. Thus, Faulkner suggests that courts balancing the burdens
imposed by an election scheme must consider evidence demonstrating
that a scheme actually interferes with the party's ability to organize
and campaign effectively. If the party can produce sufficient evidence,
they can object to a state-dictated candidate selection method
and the state must have a compelling justification for its electoral
The decision in Faulkner was based on broader principles previously set out by the Supreme Court in Eu v. San Francisco County Democratic Central Committee:
"a State cannot justify regulating a party's internal affairs
without showing that such regulation is necessary to ensure an election
that is orderly and fair."
So basically, in US jurisprudence, there is a balance of interests to be taken into account: fair elections stand in balance with unnecessary interference in party's internal affairs, the latter stemming from the right to political association.