How extraordinary! - a very similar thing happened to me on Monday. I spent most of the day on a trolley in the corridor of our local A&E, having collapsed and passed out with extremely severe gastric pain. Luckily the pain was controlled very quickly by the ambulance crew, and all the right investigations were done at the hospital in spite of the full corridor. I am to have a further gastroscopy - it is likely to have been a problem with the polyps that I have.
But, like the OP, I was given a prescription after the hospital pharmacy had closed. The chemist my DD took it to said they could not dispense it and we would have to return to the hospital when the pharmacy was open. In fact, my OH has managed to sort out for our GP to counter-sign it and for it to be dispensed free at the surgery, about 2 minutes from us.
No suggestion was made that we might have to pay.