Understanding that question "How could this happen?" is something that will help you understand more about the world, and may change your opinion of people whom you think are crazy.

The key is that humans act on their beliefs. Which is to say if you believe X, then the action required for situation Y is Q. Rather than be abstract about it though lets put wrap some reality around it.

If you believe your house will be destroyed in the event of a hurricane, then the action required when it is threatened is to evacuate.

Conversely, if you believe your house will survive a hurricane, then the action required when it is threatened is the shelter in place.

Two people, each holding an opposite belief about the threat to the house, will come to two very different conclusions.

Now if you layer in a belief about evacuation, where one believes that people are killed when they try to evacuate with everyone else, and one who believes that people who evacuate survive these disasters. You can set up a perfect conflict between these two people.

Person A, thinks both their their home will survive and that evacuation will kill you.

Person B, thinks that the house will be destroyed and that evacuation will save you.

Here is the kicker, if you can put the right sets of beliefs into a person you can make them do anything you want, even when it is against their own self interest. We call it things like brain washing or propaganda or "fake news" but it is all the same stuff.

It is possible to define a set of beliefs for you where you think that killing yourself and your children is the correct (or even only) choice available to you.

What is worse, deprogramming people is super hard. They have these beliefs, they have been reinforced by some mechanism, and part of that reinforcement are a layer of beliefs that prevent alternate ideas from seeping in.

Immigration is a canonical example. Characterize immigrants as murderers, thieves, and rapists, show an imminent threat of "invaders", and convince people that the other side wants to just let these people waltz into the country without restriction.

The beliefs are all carefully constructed to interlock such that people who have adopted those beliefs will take action to insure the current ruling party is kept in power in order to keep them safe.

The Nazis used this, Stalin did too, the Chinese, and now the Republican Party have all adopted this technique of constructing a belief system around immigration and "the other" that incentivizes people to act against their self interest (or perhaps more accurately to convince them their self interest is served by acting in the way the party wants them to act.)

Jim Jones did this by convincing people that he was a prophet and in touch with God. That he had a clearer view of what was happening in the spiritual world, and could advise people how to act in order to maximize their success in the afterlife. They believed that so strongly that when he told them they needed to die to move on, they considered that a reasonable next step.

Edit: One of the more interesting aspects of Jim Jones' ministry for me was how people responded when faced with the reality that they were in a cult. There is an interview of some members from one of the documentaries where the members get angry at the interviewer who is pointing out inconsistencies and risks. Rather than challenge the beliefs with the source, they lashed out at some poor reporter who was pointing things out to them. No one thought to ask these folks if they would rather feel foolish at having believed something that wasn't true, or be dead. Of course at the time they didn't realize their beliefs would get them killed exactly. In my mind that is a real tragedy, one warped leader leading all of these people to a place where their energy, and contribution served only a twisted need for loyalty and power.