Most of the criticism against drug companies is that while they invest x for R&D and actual manufacturing, they earn back at least 100*x in profits. I don't think there are many other industries that allow this to happen.
I'm not entirely familiar with what makes pharma patents that much different from software (you don't really have a monopoly even if you own a software patent), but that's basically what's happening.
Once a company gets a patent, free market rules no longer apply, and they are free to price their drugs as they want.