Rav Hirsch points out that the situations were different. For example, at Mara they came and found water that was impossible to drink. After Eilim, they found themselves in the dessert with nothing visible as to how they would be given food or water. As slaves they had been accustomed to their masters making sure that food and drink were always available. They had not yet learned that Hashem was indeed providing for them. In fact, Hashem was already about to provide them with the man.
As Rav Hirsch explains in Beshalach 17:5:
In these two verses, Hashem tells Moshe what would have occurred even
without the people having "complained". They were to be given daily
only and exactly the requirements for that day to accustom them to
look up to Hashem, with confidence for the so-called petty necessities
of daily life, and to impress them with the certainty that each
individual man and each man's individual home is a special object to
which Hashem gives his attention:
Rav Hirsch points out that at Rephidim, they were indeed punished for panicking as Amalek attacked them when they lost control and started running to the well of Miriam. This was part of the lesson that they were supposed to learn.
Verse 17:1
The entire community of the children of Israel journeyed from the
desert of Sin to their travels by the mandate of the Lord. They
encamped in Rephidim, and there was no water for the people to drink.
They still had water but had been accustomed to finding water already available. Here they complained (as Rav Hirsch points out)
Here they were not yet making reproaches, did not refer to their
requirements, but as a justified claim, demanded water. Where we camp
there must be water.
Later in verse 3, Hashem let them get thirsty to show them the lesson.
The people thirsted there for water, and the people complained against
Moses, and they said, Why have you brought us up from Egypt to make me
and my children and my livestock die of thirst?
Rav Hirsch shows that
From Rephidim to Horeb is but one station and from these verses seems
to have hardly been a day's journey. It seems that, had it not been
for their untimely murmurrings, Hashem would have let them feel the
scarcity in Rephidim and let them move on to Horeb, which was the real
goal of their wandering in the wilderness, and then there at Horeb, He
would let water gush out of the rock for them.
Similarly, at kadesh they were suddenly faced with the loss of the well that had accompanied them for forty years and which they assumed was their due. The sudden shock of the loss caused them to think that Moshe had made a mistake.
Chukas 20:2
The congregation had no water; so they assembled against Moses and
Aaron.
On the other hand Beha'aloscha 11:1
The people were looking to complain, and it was evil in the ears of
the Lord. The Lord heard and His anger flared, and a fire from the
Lord burned among them, consuming the extremes of the camp.
Rav Hirsch translates
וְהָֽאסַפְסֻף֙ אֲשֶׁ֣ר בְּקִרְבּ֔וֹ הִתְאַוּ֖וּ תַּֽאֲוָ֑ה
But the rabble that they had taken in amongst them goaded themselves
on to desires
Which means that they deliberately tried to pretend to have complaints rather than being faced with problems that they had no precedent for dealing with. They were just attempting to make an excuse to complain.
Similarly in Chukas 21:4
וַיִּסְע֞וּ מֵהֹ֤ר הָהָר֙ דֶּ֣רֶךְ יַם־ס֔וּף לִסְבֹ֖ב אֶת־אֶ֣רֶץ
אֱד֑וֹם וַתִּקְצַ֥ר נֶֽפֶשׁ־הָעָ֖ם בַּדָּֽרֶךְ
Rav Hirsch translates as
and the soul of the people was impatient of the way
That is they became impatient as to the way of traveling and complained about something that they had regularly for the past 40 years. As a result, Hashem showed them that the ease and comfort that they had become accustomed to over the past forty years was an illusion. If they did not have the לֶּ֖חֶם הַקְּלֹקֵֽל
and all the nissim that protected them, they would have been subject to the natural dangers of the dessert (like the fiery snakes).