It is not legal if the dementia makes your mother "incompetent"--not aware of the nature and consquences of her actions. The bank may not have noticed your mother's incompetent status. You should document as much as possible that your mother was suffering dementia before the signing. You may have an obligation to notify the bank of your mother's status so that they can take other means to secure their interest. You should consult with an attorney.
At your service,