To vote in the Democratic primaries for New York State, I had to register in the Democratic party. Why would a political party hold a closed primary?
If you are a diehard Republican, you may be tempted to vote in a Democratic primary in order to boost one of their candidates that you believe may have a more difficult time during the general election than the other. I have had republican friends telling me they keep cheering Bernie Sanders on, because in their perspective he will have a harder time getting elected than Hillary Clinton, for example. This would be a bigger deal in election years where one party has a contested primary and the other one doesn't (meaning there's not too much of a reason for people to go vote in one of them, so why not vote in the other?). This happens generally every other presidential election cycle, since a president who can run for another term generally does so with their party's support.
Besides this fear of crossover voters 'stealing' the primary away from people who actually are in the party, one bonus purported from here is that a closed primary tends to let candidates talk more openly about their views during the primary since they are largely just speaking to their base. This could let the party know more about the attitude of their base by seeing which candidates get better reactions from the issues they choose to support. It should be noted that some look to this as one of the failings of the closed primary; politicians should stand for issues that are good for all of their constituents, not just those in their own party.
You hear pundits talk about the general election 'pivot' because of this, and why I'm not sure you can really take anything anyone says at face value during a primary election anyway. Of course, as that link states, there's not much stopping me from changing party affiliation at any time and voting in whatever primary I choose. "Ultimately, the parties must trust voters."
Lastly, here's a quote from Bernie Sanders printed by the NYTimes that points out in a closed primary, people who choose not to affiliate get left out:
“Today, three million people in the state of New York who are Independents have lost their right to vote in the Democratic and Republican primaries,” Mr. Sanders said standing alongside Mr. Cantalupo. “That’s wrong. You’re paying for this election. It’s administered by the state. You have a right to vote. That’s a very unfortunate thing which I hope will change.”
In my home state, the primary election is semi-closed, meaning independents can choose to vote in either the democratic or republican primaries. The only catch is that, if there's a run-off in either, you can only vote in the run-off for the primary that you actually voted in.