A third man was killed inside his cell and four others wounded in the grenade attack by a Gaza City prison guard, medical and security sources said.
One of the prisoners slain in the city's main Shifa Hospital was in the intensive care unit at the time.
The violence followed a warning to Palestinian President Yasir Arafat from former security chief Muhammad Dahlan, still a powerful figure in Gaza, that unrest would spread unless anti-corruption reforms were implemented.
"It is time for Yasir Arafat to punish the corrupt," he told al-Arabiya satellite channel on Sunday night, in some of the sharpest criticism yet of Arafat's resistance to cleaning up high-level corruption in the Palestinian Authority.
Palestinian areas have been rocked by upheaval in the past few weeks, including kidnappings, street protests and gun battles between militants and security forces - the gravest internal challenge to Arafat since he returned from exile a decade ago.
"I do not deserve to live. I deserve execution. I am guilty. I once tried to commit suicide but failed"
one of the dead 'collaborators'
in a 2001 jailhouse interview
The disorder reflects growing discontent and dismay at Arafat and his leadership before Ariel Sharon carries out a "planned withdrawal" from Israeli occupied areas of the Gaza Strip in 2005.
Some Arafat loyalists have accused Dahlan, seen in some circles as a potential successor to the Palestinian president, of being behind the crisis.
Monday's events unfolded when a prison guard hurled two grenades into a cell inside a Palestinian security compound where those accused of spying for Israel were being held.
Later, a group of men stormed into the al-Shifa hospital and shot and killed Mahmud al-Sharif, one of those injured in the prison attack, even while Palestinian police were stationed outside, medical sources said.
Walid Hamdunah, another victim of the grenade attack, was shot and killed in the intensive care unit shortly afterwards.
Sharif had been sentenced to death for giving Israeli intelligence services information that led to the assassination of an Islamic Jihad leader, Imad Aqil, in 1995, security sources said.
"I do not deserve to live. I deserve execution. I am guilty," Sharif told Reuters in a 2001 jailhouse interview. "I once tried to commit suicide but failed."
Hamdunah was accused of being an Israeli informer and worked with a Hamas organisation.