Are you serious? It's pretty clear that its the result from long-term bullying (from everyone white or black) due to his sexual orientation and race.
It doesn't mean he was "mentally ill" to start with, but long-term, sustained bullying could very well have messed up his life and mind. I blame society and culture for that.
This is what he alleges. We don't really know exactly what he experienced. There isn't yet secondary evidence to corroborate this. Other people are saying he was a perpetually difficult and confrontational person who claimed things that weren't supported by evidence.
A mentally stable person probably won't commit murder-suicide even as a result of long-term bullying. They probably won't feel like this is the only way to calm their anger and achieve even a moment of peace. Especially not when the victims are people whom they haven't interacted with for a couple of years. The actions of a completely unrelated person like Dylan Roof would normally not be a factor.
I can't say what mistreatment he did or didn't experience. Someone with delusions of paranoia and a persecution complex may see mistreatment where it doesn't exist, or at least be more sensitive to unintentional slights. Real instances of mistreatment may be magnified many times. They may well claim real social issues as their motivations, but that context could be less the cause of their distress and more the filter through which their acclimation to distress is rationalized.
This is all just one possibility. We don't really know. What we do know is that actions such as his are very rare and therefore very exceptional, and should be looked at exceptionally.