Prison staff failed to investigate dementia of inmate who died awaiting trial for sexual assault