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.
On the other hand, how high is the marginal rent of a kitchen at home? It's usually included whether you use it or not - and some parts like the fridge would take up space even if you exclusively ate out.
If you compare the cost of renting a room in a house, and renting an apartment it is a little easier to figure out. Usually room rentals will charge extra for kitchen access or just ban it outright.
It's not the case in many other places in the world. The ratio of cost for cooking vs. eating out is uniquely high in the US.
It's not an iron law, it's downstream of a hundred things, like property prices due to restrictive zoning, baumal's cost disease driving up wages, onerous regulation on food service, and a populace that seems to have collectively given up on seeking the best value for dollar.
Why should this be the case in principle though? Do economies of scale not apply to food preparation?