Individual companies of course can and do do all kinds of things that may not be most profitable, but in the long run it's survival of the most profitable. Those get the most capital and thus have the most power of towards which goals resources are allocated.
Also companies, especially public companies, are typically mandated by law to prioritize profit.