If a mentally unstable person committed suicide would they still be punished by Allah?
God judges each person according to their own circumstances and limitations. So if a person commits suicide when they are mentally disturbed and not responsible for their actions, then God would judge that differently from someone who chooses to do it in cold blood.
What we know for certain is that God is more fair and just than any human, so there is never any need to worry about God being unjust to someone; it is God Himself who invented the very idea of justice by creating a universe in which such concepts make sense. We can trust God to be more just and kind than the most just and kind humans in history.