> to keep their employees in the office longer.
At the office, maybe, but definitely not working.
For dinner, the set times provide natural day boundaries with a strong incentive to wrap up by a certain time. During lunch, it may be saving some time that people wouldn't work by doing away with the need to get to and wait for a restaurant (if the company wouldn't provide any cafeteria at all; every place where I worked had one, usually paid and lunch-only though).
I believe that companies provide food because it's a relatively cheap perk providing a lot of value that simply cannot be replicated.
If I have to make my own food, I have to grocery shop, cook, and do dishes, all of this done inefficiently at small scale and out of my own time. At a buffet-style cafeteria, you just walk in, grab food, eat, drop off your dishes, done. The real value isn't the free food. It's the convenience that comes with it.
At the same time, it doesn't cost the company that much. Raw ingredients aren't that expensive, and neither is running a cafeteria if everything is prepared at scale.
Even if you ignore the cost, restaurants (including buffet style ones) can't replicate that convenience: They aren't at a place where you are anyways, and payment adds extra friction. A la carte restaurants are right out because of the wait. And even if the food actually did make people stay longer - I bet that time is made up by not having to do chores to feed yourself.