We don't know exactly what Nietzsche suffered from. He was initially diagnosed with tertiary syphilis but some now doubt the correctness of this. His symptoms in some ways seem like a form of dementia, and within a few years of his first collapse in January 1889 he was non-verbal. This wasn't immediate though, and he wrote several letters of a bizarre and rambling nature after his collapse. Dementia seems inconsistent with the fact that he was writing philosophical work that was pretty lucid in the months before his collapse. It's been speculated that he may have had a brain tumour which had been growing slowly but reached a size where it quite suddenly affected his mental functioning. The Stanford Encyclopedia entry on Nietzsche's life and works https://plato.stanford.edu/entries/nietzsche-life-works/ has some more details and also many suggestions for further reading about his life.