A prisoner had "foam coming out of his mouth" and had seizures in his neighbour's cell before he died, an inquest has heard.