You'd be looking to criminalize rational behavior - a difficult and quite often counter-productive endeavour.
First, there's survivorship bias. The hospitals that eat the costs of saving lives eventually go under or can't compete with the ones that invest in better doctors, equipment and so on. What you see in the end is lots more hospitals who are willing to withhold life-saving treatments than ones that will treat anyone no matter what. We may in theory want everyone to be treated, but in practice, our market behavior of seeking cheaper treatments and better doctors sways hospital behavior as well.
Second, there's unintended consequences. A hospital going under to save some lives can have disastrous consequences on the rest of the community - non-life-threatening issues turn into fatalities with the hospital gone, leading to more lives lost than if the hospital was "cold-hearted" and "calculating". Hospitals are faced with this moral dilemma every time they do their budgeting.
Third, there's utilitarianism. Is saving one life no matter how costly the way to go? What if you can save two lives for the same price? Is saving an old person's life the same worth as saving a young one's? What about "saving" someone's life but leaving them functionally crippled, vs dealing with non-fatal conditions in people which might bring them back to full function? How should a hospital spend its finite resources?
When you mix in all these concerns with the practicalities of the situation(noone is working with perfect information, and hospital staff often has to make snap judgements), you're bound to get different outcomes, including sending people home to die, depending on how the hospital lands on this balancing act.
It's difficult enough to craft a law to deal with the moral issues, but then you also need to think of the legal issues in enforcing it, and how the enforcement could lead to further unwanted consequences. Then, purely from a utilitarian POV, think about funnelling all the costs of enforcement into a charity - which one is more effective?