You know how oil and water don't mix? The same goes for cooked eggs and aluminum foil.

Cooked eggs produce small quantities of hydrogen sulfide, which causes a reaction with unanodized aluminum (that is, aluminum that has not been treated by a chemically or electronically applied coating). The reaction produces aluminum salts, and these cause the eggs to discolor. They are still perfectly safe to eat. The same thing can happen with many light-colored acidic foods.

In the future, assuming you can't cook the eggs at the last minute, cover the casserole with a stainless-steel cover, an anodized-aluminum cover, or another non-reactive cover. And to keep the eggs from setting up as they wait, you can stir in a little cream, milk, or broth before popping them in the oven.

The alternative, of course, is to do just as you did before, only to serve the eggs with ham and eat them with a mouse or in a train or in a box or with a fox