Baked goods, like cakes, are made fresh each morning. They are served at room temperature. At the end of the day, they are thrown out because the health code says so. 4 hours is the Illinois limit.
Here's an FDA list of TCS (Temperature Controlled for Safety) foods:
From a chemical standpoint: butter/eggs mixed with sugar (even if it's cooked) is substantially different and more likely to spoil than butter/egg mixed with flour and cooked.
You should throw out cakes and cream puffs. You can donate bagels and challah bread.
Here's an FDA list of TCS (Temperature Controlled for Safety) foods:
https://www.education.ne.gov/wp-content/uploads/2017/07/List...
Note butter, whipped cream, eggs, all part of frosting and fillings for baked goods.
Here's the 4 hour window again:
https://www.statefoodsafety.com/Resources/article/category/R...