In Egypt case, the new capital looks to be too close to Cairo to give this sort of protection.
Brazil changed the capital for that purpose too, and made it masterfully:
Brazil had two previous capitals, the first is in Salvador, the capital was there for foreign military reasons: The city is a natural fortress, to attack Salvador by sea you need to navigate inside a bay that has cannons on both sides of the entrance, and the coast is VERY high (Salvador major landmark is a elevator, that take people from the coast to the city proper... obviously a invader army cannot use said elevator, it was deliberately designed to not support an army).
Later it was moved to Rio de Janeiro, because Rio de Janeiro was the new focus of economic activity, mostly for agricultural reasons (Brazil southeast is much more fertile than northeast, also in southeast countryside you could mine gold).
Currently, São Paulo-Rio Megalopolis has 40 million people (out of 200 million on the whole country), crammed in 0.5% of the country territory.
And precisely to avoid this, the capital now is Brasília, Brasília is in the middle of nowhere, to get there by road you cross hundreds and hundreds of kilometers of roads bordered by forests, tiny villages and farms, the only actual "reasonable" way to get in or out of Brasília is by plane, in fact when Brasília was first built, all construction materials that could not be gathered on-site had to be shipped by plane.
And the city itself was designed in a way that the population cannot take over, the government buildings are wide apart, there are lots of sniper spots on said buildings (ie: defenders can snipe attackers easily), and it also allows tanks to roll around as necessary.
We have unrest here in Brazil, tomorrow, I expect many thousands to take the streets to try to topple the government (most of the protesters want impeachment, but many want outright army coup, even civil war is necessary), but all of those people will be in São Paulo and Rio de Janeiro...
The government will be sitting safely in the capital, the president even called all ministers to the capital to wait, and the federal government has a separate defense militia (we have federal police, armed forces, and the "National Guard", the "National Guard" does not obey the defense minister, neither the police hieararchy, and is directly under the president, also the "National Guard" people can easily rally and wait in the capital, their numbers are only enough to defende the capital, many of their members are government supporters, and the army suspect that the National Guard was created precisely to counter the army itself.