There are many reasons why someone would go to the hospital and then not want or no longer want care. Not everyone knows what the hospital can and will provide. At the end of the day some people expect magic, others simply want a sandwich.
Perhaps this patient in particular had no one and wanted to be around others who would show compassion during her passing. You don't know what someone wants or expects unless you ask. Even then, there is no guarantee that you'll ever get an answer.
At the end of the day, you can't force care unless the patient isn't of sound mind, a harm to himself, herself, or others. But, that doesn't mean you can't be caring. There's always something to provide even if it's just kind words or a simple touch. Sometimes that's really all someone wants.
Does someone like that belong in the hospital? Perhaps not. But, he or she is there. The very least that can be done is to acknowledge him or her as a person.