President Emmanuel Macron announced on Monday that he had chosen Labour Minister Elisabeth Borne to be France’s next prime minister.
She will be only the second woman to head the French government, 30 years after the country had its first woman prime minister.
Mr Castex was a surprise choice for the role in 2020 and his departure will give Mr Macron the opportunity to reshape his Cabinet before crucial parliamentary polls in June.
The centrist president will need a legislative majority to push through his domestic agenda following his re-election — with a new left-wing alliance and the far right threatening to block his programme.
Speculation had been rife in recent weeks about Mr Castex's replacement, with Mr Macron indicating he wanted a woman with left-wing and environmental credentials.
Those criteria reflect his desire to focus on schools and health in the early part of his second term, as well as the climate crisis, which he has promised to prioritise.
Ms Borne, 61, is seen as an able technocrat who can negotiate prudently with unions, as the president embarks on a new package of social reforms that risk sparking protests.
France's first woman prime minister, Edith Cresson, told the Journal du Dimanche newspaper that French politics remained “macho”.
Ms Cresson headed the Cabinet from May 1991 to April 1992, under president Francois Mitterrand.
“She'll need lots of courage,” Ms Cresson said.
Mr Macron, 44, registered a solid victory in April 24 presidential polls against far-right leader Marine Le Pen, winning by 59 to 41 per cent.
Ms Le Pen and defeated hard-left leader Jean-Luc Melenchon are both eyeing comebacks in the parliamentary elections on June 12 and 19 that would give them the ability to thwart Mr Macron.
Mr Melenchon recently persuaded the Socialist, Communist and Greens parties to enter an alliance under his leadership. This unites the left around a common platform for the first time in decades.
Mr Castex, 56, had intended to resign immediately after the presidential election, in line with French tradition, but was persuaded by Mr Macron to stay on while he lined up a replacement.
A native of rural south-west France, Mr Castex's strong regional accent and no-frills style has endeared him to many French people.
He will mostly be remembered for his management of the latter stages of the Covid-19 pandemic, delivering regular TV briefings on infection figures, shutdowns and social distancing measures.