The thing I feel the need to point out is that evil and Evil are two different things in DnD. "Good," "Evil," "Chaos," and 'Law" are not objective moralistic determinations, they're actual, tangible universal forces. A wizard can open a portal to the Law dimension and get a brick of Law, and a cleric can tell you exactly how Evil any action is, because Evil is a measurable form of energy. A paladin using Detect Evil is not someone making moral judgements, they're magically determining how much Evil energy is inside people.
While a lot of it is directly related to moral choice, there are a handful of things that out-and-out alignment-based. The classic example is someone who uses mindless undead run farms and do hard labor, so the people don't have to suffer and starve. This action may be good, but it is definitely Evil, because necromancy uses negative energy, which is tied to Evil. So even if they're a morally upright person, they still can't get the patronage of a Good god, and they still have the Evil alignment.
Summoning a demon is a distinctly Chaotic Evil act, because demons are beings literally made of Chaos and Evil, and technically is grounds for an immediate alignment shift. It doesn't matter WHY they did it, because it's like rolling in mud and thinking you won't get muddy.
That said, there are other considerations. Firstly, an alignment shift doesn't automatically mean a shift in personality. It can, of course, but it can also be that the Lawful Good person will simply continue to act Lawful Good, and their actions will generate enough Good and Law to eventually counteract the Chaos and Evil inside them, at which point they will shift to True Neutral, and then back to Lawful Good. Alignment doesn't mean a lot unless they're a class that's alignment-dependent (like a Paladin or Monk), then they would lose their class powers until their alignment returned to normal, either via the way I mentioned, or by appealing to their deity or patron concept (Depending on your version, Paladins can be servants of a god, or a greater ideal, so a paladin could appease the greater concept of Good for forgiveness).
Secondly, inadvertent consequences don't count. In order for an action to affect your alignment, you have to understand, to some degree, what you're doing and what it will do. So summoning a demon on purpose of Chaotic Evil, regardless of why you do it, because you're still knowingly bringing an agent of Chaos and Evil into the world, but, say, smashing a magic rune without knowing that it's binding a demon is (reckless and stupid) not Chaotic Evil, because you're not knowingly and willingly serving the cause of Chaos and Evil. It's the same reason animals don't have an alignment - They lack the level of higher thought to understand their actions on a moralistic level.
Of course, as others have said, you're the DM, and you can take or leave all this as you see fit. It's your game, so as long as you're fair with your players and keep things consistent, do whatever.
tl;dr Good and Evil are tangible forces capable of directly manipulating the world, and they only care about what you did, not why you did it.