I have read no less than six different explanations of why aluminum foil sometimes sparks in a microwave. This is my best guess: Microwave ovens operate at about 2.45 Ghz. Water absorbs the non-ionizing radiation and becomes more active, creating heat. But aluminum foil, like all shiny metal, does not absorb microwaves - it reflects them.
Because the microwave energy is limited to the surface of reflective metal, only the surface electrons of the aluminum foil are excited (although if the foil is REALLY thin, it could transfer surface excitation heat to the food beneath).
Loosely bound to their nuclei, mobile among molecules (which is why metal carries electric current well), and driven by the microwave magnetron, these excited surface electrons set up currents and electric fields.
If there are sharp edges and crinkles in the metal, the fields intensify there. This is because electrons, which all have like charge, want to avoid each other, so in the absence of a positive charge to attract them, they flow to narrow sharp edges where the electron population is not as numerous as on the flat surfaces. Intensifying fields at sharp edges may create enough potential difference to cause a current to jump to the microwave oven's metal walls.
Microwave ovens are designed to discourage such antenna-like behavior, but if a current does jump through the air within the oven, it may exceed the dielectric breakdown strength of the air molecules (30 Kv per centimeter) and strip electrons from them, ionizing the air through which current travels. When the air becomes a conductor, it creates a spark. If the circuit breaker doesn't blow, an electric arc may appear.