You are employed because the company expects the profit/savings you generate to exceed the cost of employment. If that stops being true, then naturally it's no longer profitable to employ you.
You'll notice there is no mention of the overall profitability of the organization in that equation. It holds equally true for both profitable and unprofitable orgs.
Obviously the world in messy, and it isn't always clear whether a given department or unit is or will be profitable.