After the SHPs and Vegapunk/Giants have now left Egghead and were able to almost flee in a most spectacular way, we now have this chapter of mostly a flashback. The flashback has a very specific purpose. Because, if we are looking at how exciting and tension building those last chapters were, we have now one, which absorbs this excitement a little and gives us some kind of calm to be able to breath. It loosens the tension in this way very well.
Looking at its content, we see that Oda fixates on giving us a flashback about how Vegapunk managed to find out that York was the traitor and how they implemented the plan, we saw has played out almost well.
While the Stella, Shaka and Pythagoras did not take measures against the traitor (York) or also did not erase their memories right at the beginning of the two weeks, has made some people question them. However, there are a few specific reasons for this approach.
The three of them did not know in the first week, who the traitor was and what he/she wanted. Any measures taken during this time would have meant poking at an unknown danger in the dark or even ignoring it, if they had erased their memory then.
After figuring out about York and her betrayal, everything was clearer. Here, the most intelligent path they could have walked, if the Stella had decided that he wanted to live, was to flee.
Contrary to that, the Stellar decided against life and to sacrifice his body (not his brain) for the possibility to counterattack the WG. Note that this is an active path and not the defensive one of just fleeing. And if you watch, just how essential this counter attack is to the entire world: Now, the world knows about what awaits them and many people can prepare themselves for the rising of the sea level. Vegapunk’s speech had great influence on the world and its habitants to a degree that preventing the speech from happening would have been detrimental to everyone’s benefit. If the WG or York would have found out about the speech, than the WG could have found measures to suppress any information from spreading - just like they did in Ohara.
Additionally, Vegapunk knew his death was meaningful, as this was, what he wanted.
So, it was of utmost urgency that York or any other person from the WG did not get information about their plan. And this is the only reason all three erased their memories: They did not want their newly implemented plan to be leaked to the WG in any way. This was their trump card. You can also say that the necessity of not revealing what they knew rose with the implementation of their plan into limitless hights. This is why they erased their memories only two days before the now and not earlier.