The history of the current primary system is rooted in the Progressive movement of the early 20th century. Many state governments decided that there was a public interest in standardizing the selection of candidates in the political parties, and removing (or lessening) the influence of local party bosses in the process.
Their reasoning was that while the parties themselves are essentially private organizations, the state has a duty to ensure the transparency of the democratic process, and therefore the parties would be subject to such regulation as the state desired.
Sometimes even for the same jobs. Elections for local bodies like city councils often have multiple slots available at once, and depending on how it’s set up, a single voter might vote on multiple council members, in which case you might indeed vote for members of both parties for the same job.
Some voting machines do have an option to vote “straight party”, casting all of your votes for all of the offices for a single party, with the push of a single button, but use of that single button is never mandatory. You can always choose to go through each race individually, and vote for the Democrat one place, the Republican another, the Libertarian for some other office, and the Socialist in yet another.