Everything is a market. Someone has to produce a finite supply for some cost. There is some demand for the medicine. Suppliers can be incentivized to produce by demand through price.
Look up the percentage of all drugs that were invented in the United States. Socialized medicine is subsidized by capitalist innovation overseas. There are so many problems with the US system, but they have more to do with regulatory capture (including difficulty of FDA approval + difficulty of becoming a doctor) and price transparency than anything else.