Morsi was an Islamist who became Egypt’s first democratically-elected president in 2012. The country’s military ousted him in 2013.
Morsi, 67, was being tried on espionage charges in Egypt.
He addressed the court before falling into a coma after the session concluded, state television said. Morsi was later pronounced dead. He spoke for five minutes, according to Egypt's public prosecutor.
Abdel-Moneim Abdel-Maksoud, Morsi's lawyer, told ABC News, "The authorities have not yet informed me about the procedures that will follow [Morsi's death] but we are in contact over the matter."
A senior leader of the Muslim Brotherhood, Morsi came to power after winning Egypt's first democratic elections in 2012. His tenure lasted for just a year after the military ousted him following massive protests against his rule.
The Brotherhood was then outlawed and Morsi and most of its senior leaders were imprisoned. The former president received multiple prison sentences on various charges, including killing protesters.
"Dad, with God we meet," his son, Ahmed Mohamed Morsi, wrote on his Facebook page.
The public prosecutor said in a statement that a forensic report on Morsi's death would be published.
"The public prosecutor has ordered that a team of (investigators) be dispatched ... to examine surveillance cameras in the court hall and listen to those who were present with him (Morsi)," the prosecutor said.
Former defense minister Abdel-Fattah El-Sisi, who led the military ouster of Morsi, was elected president in 2014. He launched a crackdown on the Brotherhood, which the state has accused of carrying out attacks on security forces.
The Brotherhood denies resorting to violence, saying it's committed to peaceful activism.
Rights groups have repeatedly criticized the conditions of Morsi's detention as he was largely held incommunicado. His family allegedly was denied access to him.
In June 2017, his family told Human Rights Watch he had "fainted twice and experienced a diabetic coma." Egyptian authorities insisted he was given proper medical treatment.
In April 2018, a group of British lawmakers who had requested to see Morsi but were rejected by Egyptian authorities wrote in The Independent: "If Morsi is not provided with adequate medical care soon, the consequence could be his premature death. He is at risk of liver failure, caused by not receiving the medical treatment he is entitled to."