I'm going to guess that the drugs aren't made continuously -- that the same production facilities are used to make several drugs. If a particular drug runs out of inventory before another production batch is scheduled to be made, or a batch run for drug A is delayed while an order for a more profitable drug B is filled, then a shortage happens.
The solution would be for hospitals and distributors to maintain a bigger inventory, but it makes for a better news story to blame manufacturers.
No matter what the level of output, though, there is always a price that you can sell it at where there will be no shortage. Either the manufacturers are behaving irrationally by selling it for less than they could, or there is some restriction on their ability to determine the price. I am betting on the latter since this is a new phenomenon. Typically when you suddenly have a malfunctioning in the market of some kind, it is the result of regulation. Factors causing market failures which do not result from regulations don’t suddenly appear out of nowhere. Either they exist or they don’t.