They usually don't know what the cost would be.
I once went to a walk-in clinic once for a cold, and they told me upfront the cost for the visit with co-pay (~$40 or something). Several months later, I hear from their collections office.
Apparently, as they told it, my insurance company declined to pay their part of the co-pay because they insurance company claimed it wasn't part of routine care. Absurd.
Anyways, the clinic's response was to retroactively increase the price they charged me. But because I paid in cash, they couldn't just take it from me. So they spammed an old mail address from when I was in college (poor student with the current PO box), and then called me on the phone. And the amount was only $10; far less than their staff time.
Zero part of that seems square with common law. When is it possible to change a price months after a transaction? None of this makes sense, but if they have beef with the insurer that's on them.
So if the hospital tells you the cost up front, and they're wrong, they stand to lose money if they can't swing the negotiations with the HMOs.
The US system just makes no sense.