In a lot of cases it's simple price fixing. If you want to be shocked, compare the prices of frozen potato products (like bagged hash browns and french fries) to the price of potatoes. There's like a 200% premium for simply cutting and flash freezing them. The machines have got to pay for themselves in an hour.
They do and companies already take advantage of them. But even a fast food restaurant has a ton of additional overhead that you won't have by cooking at home (or some you won't include in your price of your homecooked meal): rent, salaries, utilities, taxes, shrinkage, maintenance, etc. So even if they can get the ingredients cheaper they can't compete with you on some of these factors and must also include others like utilities in the cost of the finished product where you will generally ignore them when thinking about how much it costs to cook dinner.
Once you factor in rent, then cooking at home is maybe not cheaper. Rent and mortgages is the black hole sucking all money from the restaurants. Not ingredients or wages.