The law that allows them to do this is the body of laws around contracts. You sign a contract of treatment that says you'll pay what they decide you owe. If you don't sign it, they won't treat you.
>If they don't tell you the price beforehand, and they don't publicly post the prices, legally, how do you ever owe them any money?
If you ever go to an actual hospital, you'll see how absurd this question is. First, there are never any prices posted. Second, good luck even getting an answer about how much anything costs. A friend had to try three different facilities (thankfully a non-urgent matter) before he could even find a facility where they could quote a price.