People with mental health problems sometimes ended up in the cells for the night when they should have been in hospital.