That is interesting, if you have some links or hints, pls let me know for i'd be really interested in reading about such a topic!
Try searching EnWorld for threads on balance. I went looking for a good one to read but couldn't find one, but I do know the topic came up often enough in the past that people complained about it and all the arguments that it caused.
Let me start with your summary question and work into the details:
...ok and this brings me back to the original question: it not only a matter of mastering, it is also a matter of balancing in game design... and the question is again: why?
I answered why in my first response to you. Because unbalanced encounters make for encounters with few meaningful choices and as such are simplistic encounters and encounters that take no particular skill to design (though more on that comment later).
i am complaining about the fact that whenever you have a 7th level party, your adventure is always "railroaded" in terms of encounter: never a monster where the wisest thing the party can do is to flee
I get what you're complaining about but you seem to be complaining in the face of reality, making your own claim into a straw man. You began this thread by citing 3e as an example system where that was true, but another poster immediately and correctly countered that even the suggested guidelines for EL pushed the GM to place encounters well above party level 5% of the time. And those were just guidelines, and not rules. Moreover, I can think of several examples in official WotC published modules that did in fact present an encounter where the wisest thing the party could do was flee. For example, in the introductory modules to 3e, in the second module 'Forge of Fury' there is an encounter with a CR 10 roper where the PC's are expected to be 3rd level. Ropers are seriously dangerous monsters and at 3rd level if you try to go toe to toe with one you will die horribly and messily.
So the heart of your complaint is simply false.
My point is also try to train the players to "read the situation" and take decisions that ordinary rules would consider negative in terms of experience (like withdrawing) whereas they should be calculated in the exact opposite sense: a combat would turn in a likely death and a withdraw would imply the pcs survives.
Yeah, we all get that but I'm telling you that this is not an easy thing to do and often is a sign of dysfunctional GMing. If a novice GM introduced this idea to me as if it was novel and new and really exciting, I'd very much ask them what is their real motivation here? Because there is so much good advice doing this ignores. Even that Roper is Forge of Fury is controversial because a new player has no means of reading a situation and knowing just how dangerous anything they meet is. Experienced players may have out of character knowledge that this is a roper and respond by metagaming, but novice players won't have that information and metagaming isn't necessarily fun for the players.
It is very hard in many cases to telegraph to the players what the situation is. A 1st level bandit looks just like a 10th level bandit. A group of 1st level bandits looks just like a group of powerful werewolves.
One of the worst impulses you as a GM can have is the impulse to go "gotcha". GMs should try to avoid cultivating any particular enjoyment out of encounters where the fun of the encounter is going "gotcha" to the players because they acted with insufficient knowledge, because very quickly that impulse will lead you to creating a series of encounters that are only fun to you the GM. And GMs are there primarily to make sure the players have fun, not to make sure that they have fun. That isn't to say that the players can't fail from time to time, but if you are cultivating enjoyment out of the player's failure beware - that is the path to the dark side of GMing. When a player makes an error and leaps without looking, it should be like when a good mystery writer reveals the mystery and the reader has the satisfaction of realizing the writer played fair, gave out the clues, and they should have seen this coming because it had all been revealed if only they had the skill to put it together. Puzzles where there wasn't enough information to actually solve them aren't fun. Gag puzzles that can't be solved are only fun for the person handing out the gag.
Likewise, it's a good guideline of good GMing that you the GM should never create a scenario where the players have a choice that you can't stomach them making. Sure, you may be thinking how fun it is going to be if the players read the scenario and flee from the overpowering monster, but what if they don't? Then what?
Why do you tie fun with success?
Because failure is not fun. Every counter-example you are going to give me is going to have one of two attributes. Either it is going to be about how the possibility of failure is necessary to enjoy success, which is true but which doesn't prove failure is fun. Or else you are going to propose an example of partial success where the things achieved greatly out weight the cost of the things lost. For example...
Even an episode where a PC dies could be perceived with fun.
Yes, this is a well discussed topic. This is the concept of "the good death". The good death is one where even though the character died, they achieved success in death by having such a heroic meaningful death that their story arc is fulfilled. A very famous example of a good death is Darth Vader's death at the end of Return of the Jedi where he not only in death defeats the villain, but also redeems himself and restores the relationship with his son - whose faith in his goodness was critical to his redemption. This is a full and complete and satisfying story arc and most players with a narrative aesthetic of play would love to earn a death that meaningful and glorious.
But that a death can be "narratively good" in no way whatsoever implies that deaths from imbalanced encounters are good deaths. They are generally meaningless deaths.
And lets be very clear. If your the GM put your thumb on the scale and weaken the danger of the encounter by not playing the foe in a deadly manner, or not playing the foe in an intelligent manner, or by putting the PC's into a greatly advantageous situation that mitigates against the normal danger of such an encounter, this is no longer an imbalanced encounter. If you have 3rd level players meet a CR 15 dragon that has just eaten a wooly mammoth and is feeling placid and susceptible to bribery or flattery and generally lazy, well fed and tolerant, and you allow the PC's to survive this encounter by fairly easy social checks or running away using skills readily available to a 3rd level party, then that's a CR 3 challenge - not a CR 15 challenge. And yes, it requires some skill to make that challenge, but that's because it always requires skill to make a balanced challenge. It takes no skill to pick a foe massively beyond the party's strength and throw that at them.
In short, I think you are weaseling out of the terms of your own claims. If the goal is realistic encounters, then that CR 15 dragon is more likely to be hungry and greedy than it is to be in a rare tolerant mood, and there is nothing that a 3rd level party can do to run away from a CR 15 dragon that wants to kill them. Nothing. They aren't fast enough. They aren't stealthy enough. And they will all die. And they won't have heroic or meaningful deaths. They'll just die. Realistic? Maybe. It certainly happens to lots of NPCs. There is no fun here. There is no fun when the 12th level bandits bully 4th level PCs, unless the joy is by the GM who enjoys being a bully.
Reading the situation and knowing whether or not these are swaggering overconfident 1st level bandits or swaggering overconfident 12th level bandits is basically impossible. And if you say, "Well, I'd allow a throw to tell if they appear to be competent fighters.", then you are basically creating a save or die trap that isn't even a particularly interesting save or die trap. There is no "fun" in reading that situation. There is no fun in metagaming against the GM, least of all once it becomes clear that the GM is using reverse logic or reverse reverse logic because they are addicted to going "gotcha".
If the way you present that event leaves room to survive with a huge defeat of the PC, why the fun should be wasted?
Because realistically why should you present such an event as leaving room to survive? And if you are leaving room to survive, that is to say if you are as a GM putting your finger on the scale to help ensure the PC's survive, first of all what is the point of you fudging like that - who is having fun in that situation other than you? And secondly, if your finger is on the scale such that this is effectively a hazard to be avoided, why would you treat it as if it really was an unbalanced encounter?
Why the fun should be only meet and defeat a pack of rats when the party is at 1st level?
Strawman argument. No one is suggesting that at all, nor is there any examples of that in popular modules for 1st level characters.