It seems unusual that while many states tend to reliably lean one way or the other, there are a few whose populations vote unpredictably. Is there a historical reason for this? Have other swing states existed in the past?
Swings states often don't have unpredictable voting patterns, they are simply more evenly divided. As a basic model, think of three states. A is 45% Democratic voters, 35% Republican voters, 20% swing voters. B is 45% Republican, 35% Democratic, 20% swing. C is 40% Democratic, 40% Republican, 20% swing. For the Republicans to win A, they need to convince a full 75% of the swing voters, while they only need to convince 25% of swing voters to take B, and 50% to take C.
Convincing 75% of the swing voters is very difficult, so A will almost always vote Democrat and B almost always Republican. Convincing 50% is much easier, so C will swing between the parties, even though it has the same proportion of swing voters and they vote exactly the same as in the other states.
New Hampshire and Iowa are both considered Swing States and are both in regions that primarily vote for a certain Party (New Hampshire is in the New England area that primarily votes Democrat vs Iowa is in the Midwest/Plains area that primarily votes Republican). This is in part due to the fact that they are the first Primary/Caucus states in the nation, and thus see more focus, and more importantly money, from Presidential campaigns which in turn props up the State Parties in each state. Nevada, and to a lesser extent South Carolina (it was more of a Swing State a decade ago), see this same thing. * Side note - Primaries are run by the State government while Caucuses are run by the State Parties and since State Parties can receive contributions from campaign this makes states with Caucuses another investment opportunity.
What a lot of people don't understand is that campaigns are massive undertakings - requiring a lot of infrastructure which requires a lot of funding. Even State Senate/State Representative races can cost a couple of hundred thousand dollars (depending on where they are run). A strong State Party is integral to local races, and with more funding creates a better chance of those people getting elected which creates a culture and narrative of people electing members of a Party overtime.