In the United States, both primary elections and general elections are government-organized events. These elections are primarily established and regulated by statutes passed by state legislatures.

Political parties can choose not to participate in a state primary election. ("Caucuses" are a well-known alternative used by the parties of some states. But the state party can even just decide to have neither a primary or caucus; for discussion of this in the context of the 2020 election cycle, see "[Republicans to scrap primaries and caucuses as Trump challengers cry foul][1]", *Politico*, Alex Isenstadt, 09/06/2019.) 

In fact, it seems the Colorado Republican party has expressed intent to cancel its primary for the 2024 election if Trump is not on the ballot, and have a caucus instead, but it is apparently disputed whether the party is legally allowed to withdraw from the primary process at this point: the Colorado Department of State made a statement that withdrawal is not allowed by Colorado law.  ("[Colorado GOP threatens to shift to caucus system over Trump ruling](https://thehill.com/homenews/campaign/4369749-colorado-gop-threatens-to-shift-to-caucus-system-over-trump-ruling/#:~:text=“You%20won%27t%20have%20to,this%20is%20allowed%20to%20stand.”)", *The Hill,* SARAH FORTINSKY - 12/20/23 12:20)

When a party choses to have a primary election in a state, it is subject to all Constitutionally valid state laws regulating the election.

Parties have First Amendment association rights that election laws must not infringe, so parties do get a say in certain things like whether non-party members can vote in the party's primary election ([California Democratic Party v. Jones][3], 2000). However, there are various other constitutional issues that can come into play, so First Amendment association rights are not a trump card in this context.

I wrote a longer post with more details as an answer to a broader past question here: [How do parties really choose candidates in the US?](https://politics.stackexchange.com/a/80635/7580)


  [1]: https://www.politico.com/story/2019/09/06/republicans-cancel-primaries-trump-challengers-1483126
  [2]: https://thehornnews.com/report-gop-to-cancel-primary-election-after-trumps-removal/
  [3]: https://en.wikipedia.org/wiki/California_Democratic_Party_v._Jones