A top figure in the now-banned Islamist movement Muslim Brotherhood, Morsi had just addressed the court from a cage at a hearing on charges of espionage.
Morsi, who was 67, had been in custody since his removal after mass protests.
The Muslim Brotherhood said the death was a “full-fledged murder” and called for crowds to gather at the funeral.
Activists and his family had long complained about his prison conditions, saying Morsi was not receiving treatment for serious health problems such as high blood pressure and diabetes, and was constantly being held under solitary confinement.
What happened in court?
Morsi collapsed moments after addressing the court in Cairo at a hearing related to charges of espionage emanating from suspected contacts with the Palestinian Islamist group Hamas, which had close ties to the Muslim Brotherhood.
He spoke for five minutes from a soundproof glass cage which officials said was designed to prevent him disrupting proceedings. The cause of death was not immediately confirmed but Egypt’s public prosecutor said an initial report showed no signs of recent injuries on the body.
Last month, his family said authorities had repeatedly denied access to him and that they knew little about his health conditions, a situation that “violate[d] constitutions applied all over the world”.
In March last year, his youngest son, Abdullah, said officials were “doing this on purpose, since they want to see him dead ‘from natural causes’ as soon as possible”.
Morsi, who became Egypt’s first democratically elected leader after winning polls in 2012, had already been sentenced to more than 45 years in prison in three separate trials, including leading an outlawed group, detention and torture of anti-government protesters and leaking state secrets.
He had always rejected the authority of the courts, and his supporters denounced the trials as politically motivated and attempts to give legal cover to a coup based on unreliable witnesses and scant evidence.