Now this may seem (and be) a dumb question, so let me rephrase it.
In modern warfare, with assault rifles, my understanding is that a unit will usually fire straight at the enemy from distance and cover, and thus flanking this unit make it extremely vulnerable (no more cover).
However, if we look at a phalanx, or a maniple, or any kind of crowded heavy infantry, I fail to see why attacking the flank would be so decisive. Those soldiers had their own cover wrapped around their arm (shield), and they could individualy turn around to face the ennemy without risking being shot from the side (not exposed to direct fire like with rifles)...
In fact, such tactics as the arrowhead formation or the echelon formation (or checkered formation) actually put both armies in the situation of mutally flanking each other, should they attack, and I fail to understand why thoses tactics were succesfull...
What am I missing ?
It's not a dumb question, but it involves some understanding of pre-modern militaries, warfare, and tactics.
For starters, the idea of the "flank" comes from having troop formations. This goes beyond safety or strength in numbers; the organization of troops into strict formations allowed them to act (and be directed as) a unit, making use of special weapons and tactics (like the phalanx you mentioned) and increasing the discipline of the army. In a conflict with large forces involved, the ability of a general to direct and coordinate blocks of soldiers led to the development of "set piece" battles...but there was a downside to these formations, as they were usually tightly packed, and directed to expecting to give and receive conflict from the front, rather than the flanks or the sides.
In Hoplites : the classical Greek battle experience for example, Hanson writes:
Thucidides says (5.71.1) that all armies tended to edge to the right, as each man sought the protection of his neighbour's shield for the unguarded right half of his own body, and there was thus a tendency for each side to create an overlap on the right. Eurpides refers to the stalemate situation which could result (Supp. 705-6), and this was, presumably, why the battle of Laodokeion was 'ambiguous' (Thuc. 4.134.1). At the Nemea, however, the Spartans appear to have deliberately exploited the tendency (Lazenby 1985:139-40), and although the result was that the left was sacrificed, this may have seemed acceptable. The left consisted of allied troops, who would not lose too heavily if they beat a hasty retreat, and the right could then take the victorious enemy right in its shieldless flank, as it broke off pursuit and attempted to retire (Xen. Hell. 4.2.22).
For the hoplite, the idea of being attacked on the unarmored side was a definite disconcerting fact - and for the actual phalanx, with its bevy of long spears, changing facing was not a mean task. But you have to also consider two other factors: the surprise factor of being attacked from an unexpected quarter, and the possibility that the formation would then be facing an enemy on two "fronts" - the front of the formation, and the flank. For the troops at the corners, this meant they were outnumbered, being attacked from multiple directions, and were likely to die, and once they died the formation would start to lose cohesion.
This idea of flanking and formation continued to develop in the western idea of war. Carl von Clausewitz in his treatise On War, for example, gives considerable attention to the flank, despite living in the Napoleonic era. At this period, when single-shot muskets were in wide use in European armies, they had already understood the concept of the enfilade (where musketmen would fire along the line of troops, as a flank but with missile weapons and, of course, with the troops in massed formation) and defilade (where the musketmen would wait in a position to enfilade troops that crossed in front of them); the naval equivalents were raking and crossing the T, and for similar reasons: the benefit of being able to fire on your enemy without receiving fire in return was substantial. It was the flank attack adapted to new weapons.
The development of the rifled musket, which was more accurate, and the repeating rifle which could fire multiple shots without being reloaded (thank you u/Flabergie for the correction) required another change of tactics, though generals were generally slow to realize it; they still thought that to mass your fire you had to mass your men. But you can see in the American Civil War how very similar tactical thinking was in play: both sides in a battle sought to extend their lines and outflank one another, because such tactics were still effective. You can see a good example of the deadly effectiveness (both in terms of troops killed and morale shattered) in the battle of Antietam. Eventually, this line of thinking of "extending the line" is what gave way to trench warfare in World War I.
However, if we look at a phalanx, or a maniple, or any kind of crowded heavy infantry, I fail to see why attacking the flank would be so decisive
As I said above, turning to meet an attack on a flank wasn't always an option - nor were flank attacks always decisive. Flanks were seen as a weakness of a formation, and attacking the flank became a major objective in warfare, where general sought tactical advantage, but it did always come down to the scrum of battle, some troops and formations could hold and did. But often, the surprise and difficulty were too much.
In fact, such tactics as the arrowhead formation or the echelon formation (or checkered formation) actually put both armies in the situation of mutally flanking each other, should they attack, and I fail to understand why thoses tactics were succesfull...
The echelon formation (especially when used with the oblique line tactic) is actually a tactical idea which is based on flanking; in the normal course of events both sides would line up fairly evenly and advance, but in echelon one side would "refuse the flank" so that one portion of its troops would get into battle with the opponent's flank before the main body of troops came into engagement. If the army in echelon formation had the better part of that conflict, then it could rout the enemy's flank - and subsequently flank the rest of the battle line, which was presumably still advancing.
"Arrowhead" formations and the like exist pretty much because of flanking as well - or more accurately, because having all your ships in a line makes is easier to enfilade them; by staggering your units approach, you're taking a risk by making the foremost units a "salient" (i.e. they could be flanked from both sides), but you make it less likely to lose as many units if enfiladed.
The "chequered" formation is an ancient Roman tactic, which is a variation on the echelon that leaves "gaps" in the line, allowing units to retreat or come forward, and had multiple tactical uses.
Which is a long way to say that flanking, while not always a knock-out, was crucial largely because of its effectiveness, even into the earl modern era and the development of gunpowder weapons.