The judgments of the LORD are always done for the good of the people. They are God's desperate cry for them to come back to Him so that they will not suffer by their own hands. God will not protect those who willingly put themselves in harm's way because they put themselves out of God's reach by living in sin. All that God does is for people to hear His voice and come back to Him. He is more harsh with the leaders, because they could lead people astray. this was the case of Moses.
Moses was to be the leader of the nation of Israel. People were to look at him and he'd be their intermediary. He was a type of Jesus. He was to be obedient in ALL things including the ritual for the covenant with God, which was circumcision. Moses had to see the extreme importance of this, for if he had not been circumcised, he would have been a stumbling block for all of Israel.
On the way from Midian, Moses received a startling and terrible
warning of the Lord's displeasure. An angel appeared to him in a
threatening manner, as if he would immediately destroy him. No
explanation was given; but Moses remembered that he had disregarded
one of God's requirements; yielding to the persuasion of his wife, he
had neglected to perform the rite of circumcision upon their youngest
son. He had failed to comply with the condition by which his child
could be entitled to the blessings of God's covenant with Israel; and
such a neglect on the part of their chosen leader could not but lessen
the force of the divine precepts upon the people. Zipporah, fearing
that her husband would be slain, performed the rite herself, and the
angel then permitted Moses to pursue his journey. In his mission to
Pharaoh, Moses was to be placed in a position of great peril; his life
could be preserved only through the protection of holy angels. But
while living in neglect of a known duty, he would not be secure; for
he could not be shielded by the angels of God. In the time of trouble
just before the coming of Christ, the righteous will be preserved
through the ministration of heavenly angels; but there will be no
security for the transgressor of God's law. Angels cannot then protect
those who are disregarding one of the divine precepts.
Patriarchs and Prophets, p. 255-6
As far as the people of Bethshemesh, this paragraph explains it best.
The men of Beth-shemesh quickly spread the tidings that the ark was in
their possession, and the people from the surrounding country flocked
to welcome its return. The ark had been placed upon the stone that
first served for an altar, and before it additional sacrifices were
offered unto the Lord. Had the worshipers repented of their sins,
God's blessing would have attended them. But they were not faithfully
obeying His law; and while they rejoiced at the return of the ark as a
harbinger of good, they had no true sense of its sacredness. Instead
of preparing a suitable place for its reception, they permitted it to
remain in the harvest field. As they continued to gaze upon the sacred
chest and to talk of the wonderful manner in which it had been
restored, they began to conjecture wherein lay its peculiar power. At
last, overcome by curiosity, they removed the coverings and ventured
to open it.
All Israel had been taught to regard the ark with awe and reverence.
When required to remove it from place to place the Levites were not so
much as to look upon it. Only once a year was the high priest
permitted to behold the ark of God. Even the heathen Philistines had
not dared to remove its coverings. Angels of heaven, unseen, ever
attended it in all its journeyings. The irreverent daring of the
people at Beth-shemesh was speedily punished. Many were smitten with
Patriarchs and Prophets, p. 589
As for Uzzah, he was punished for his distrust in God and his impatience.
The ark remained in the house of Abinadab until David was made king.
He gathered together all the chosen men of Israel, thirty thousand,
and went to bring up the ark of God. They sat the ark upon a new cart,
and brought it out of the house of Abinadab. Uzzah and Ahio, sons of
Abinadab, drave the cart. David and all the house of Israel played
before the Lord on all manner of musical instruments. “And when they
came to Nachon’s threshing-floor, Uzzah put forth his hand to the ark
of God, and took hold of it, for the oxen shook it. And the anger of
the Lord was kindled against Uzzah, and God smote him there for his
error; and there he died by the ark of God.” Uzzah was angry with the
oxen, because they stumbled. He showed a manifest distrust of God, as
though He who had brought the ark from the land of the Philistines,
could not take care of it. Angels who attended the ark struck down
Uzzah for presuming impatiently to put his hand upon the ark of God.
The Truth About Angels p. 126