I've had this "rule" drilled into me for decades; but somebody asked me recently for an explanation, which I was unable to provide.
In addition to the other two great answers here, I'll expand a bit more on the "why".
Basically, your goal is to describe your hand as low as possible and as accurately as possible, right? So you want to show partner whether you have 4 hearts or 5 hearts at the earliest moment possible, while showing other details about your hand too.
If you play 2H shows 5, then you have these choices for most hands (in base 2/1) that are game-interested or game-forcing:
1NT: 6-11, nothing else exciting to say 2C: 12+, Hearts 4 or less, Diamonds 4 or less, Spades 3 or less 2D: 12+, 4 or more diamonds, Hearts 4 or less, Spades 3 or less 2H: 12+, Hearts 5 or more
Plus the various "spade support" options, of course.
Now you've told your partner (who's mostly in the drivers seat) what you have without taking up almost any space. Your partner can then tell you their next most interesting thing: whether that is a 4 card heart suit (by bidding 2H), can explore NT, can explore all sorts of things, especially over 1NT or 2C, which are the "least informative" bids. This is a generally good idea in bidding - the higher the bid, the more space is gone, so the more information you need to convey!
2H steals all that space; after that, what can P bid? 2S to show longer spades or maybe if they're stuck, 2NT to decline but not leaving a lot of room to explore NT; or 3 level bids. Ick. If you're going to have to be in a long conversation that might end up with having to really think hard about how safe 3NT is over a 5-2 4S, you want to have that conversation at the 2 level, not the 3 level, as you have only so many chances to show stoppers or shape.
The short answer: because it's just a good idea.
Expanding a bit: One of the primary goals of bidding is to find the best game available. In no trump, game is 9 tricks. In a major suit, it takes 10. In a minor suit, it takes 11 tricks. When you find a good trump fit (8 cards or more in the trump suit), you can usually take about one additional trick with that suit as trumps than you could take in no trumps, and sometimes two.
Thus, when you find that you have a good fit in a major, you look to find game in that major, but when your best fit is in a minor, your first choice is to look for game in no trumps.
When you open five-card majors (almost universal in the United States), you are looking for a 5-3 fit. When partner opens 1S, your first priority is to determine your strength and fit with partner's suit. If you are very weak, you pass.
With a fit: If you have 4 or more spades and game-forcing values, you make the appropriate bid (usually Jacoby 2NT but there are other agreements). If you have minimum responding strength (about 6-9 points) and at least 3 spades, you make a simple raise (2S). If you have invitational strength (about 10-12 points) and 3+ spades, you make a limit raise (usually 3S but there are other common agreements). With game-forcing values and only 3 spades, you generally make a 2-level bid of some sort (see below).
Without a fit: With less than invitational values (Standard American) or less than game-forcing values (2 over 1), you bid 1NT. If you have invitational values or better (Standard American) or game-forcing values (2 over 1), you make the most descriptive bid. If you have five hearts, you bid 2H. Partner now knows you have five hearts and can raise you with 3-card support. Without five hearts, you bid the minor that best describes your hand; some pairs have extensive agreements here, but in my experience most pairs prefer that you bid the cheaper 4-card minor that you hold, and bid clubs if you are 3-3 in the minors unless you have AQJ or better in diamonds.
The worst-case scenario is invitational or better values with 3=4=3=3 shape. As mentioned above, you would tend to bid 2C here unless your diamonds are AQJ or better and your clubs are quite bad. The key thing here is that you don't lose your heart fit. Opener will rebid 2H holding four hearts, which you can raise to the appropriate level.
Because a 3-4-3-3 hand is much more suited to a Notrump than a Heart contract.
A 2H call must perforce deny 4 cards in any of Clubs, Diamonds, or Spades (unless it is a hand believed to be much stronger than Opener's, which lies outside the scope of this Question and Answer), so if holding only 4 Hearts must be the contract killing four-triple-three.
To communicate this type of hand one either responds with 1 or 2 NT, or in the cheapest possible minor suit at the two level.
If partner has 4 Hearts, responding below 2 hearts allows partner to show that second suit without any bidding problems.
If you bid 2 clubs or 2 diamonds, you are "bidding to bid." That is, you want to show near-opening strength of 10-12 points and (probably) a balanced hand. There are few chances to get to game in a minor suit with a responder holding only 3-4 cards in the suit. If both partners have minimums and no fit, you should end up in a part score (at the two level).
If you bid two hearts (opposite one spade), you are "bidding to make" (a game of four hearts). The maximum likelihood is that opener has three hearts, rather than four or two. In that case, you want to guarantee an eight card heart fit, opposite your partner's (presumed) three. Then the remaining question is whether you have the "values" (points) for game.
The bidding (and meanings) might go something like this:
Opener: One spade. (12+ points, five spades).
Responder: Two hearts (10-12 points, five hearts).
Opener: Three hearts (three hearts in hand, more like 12-13 points than anything higher).
Responder: Four hearts (Top of my 10-12 range. Let's go for it.)
With 10-11, responder would have passed three hearts. With more than 13 points, opener would have gone directly to four hearts, or bid a new suit (forcing).