How so? The products they make are different, but at the end of the day they are both industries living in the capitalist society we've created, driven by the same incentives, and largely operating by similar principles. How is it morally acceptable for a tech company to make huge margins and yet morally reprehensible for a pharma company to make margins that are smaller?
The answer to this is so obvious that I almost have to assume that you're not asking in good faith, unless your purpose is to point out the flaws in our society's views on economics. Tech companies like the ones mentioned are known for primarily producing non-essential luxury goods like smartphones or B2B services. The pharma companies under discussion are in many cases producing drugs that people must take in order to live.