The Government has a page about this aimed at visitors at:
But it doesn't cover what exactly happens in the can't pay/won't pay scenario.
Treatment in A&E (what Americans would call the ER) is free. However A&E only handle the immediate stabilisation/treatment resulting from an accident or emergency. If you have an issue that requires ongoing treatment, then depending on the severity you will either be admitted to hospital as an inpatient or follow up outpatient appointments will be scheduled. Admission to hospital is normally chargeable and so are follow-up outpatient appointments.
Similarly if you see a GP, the services from the GP themselves is free, but services they refer you for generally won't be.
There are exceptions, some services are free including most infectious disease treatments. Some countries also have reciprocal agreements with the UK that may cover healthcare that would otherwise be chargeable.
If you have to pay then according to the government you will be charged at "150% of the national NHS rate". I have no idea how one would go about finding out what the "national NHS rate" is.
I'm fairly sure the NHS won't withhold urgent healthcare or lower it's treatment standards because of the inability to pay. However failure to pay debts to the NHS is likely to be used as grounds to refuse future visas.
Edit Jan 2025: it’s probably worth mentioning that post A&E treatment in any NHS facility is not guaranteed, even with adequate health cover. The NHS has a huge backlog of patients awaiting treatment and overseas visitors to the UK are not automatically given priority. Visitors would be wise to check the process for getting referred for post A&E private health treatment with their health provider before travelling to the UK.