Energy of Electromagnetic Radiations is given by e=hc/λ. Implying shorter the wavelength more the energy. Cooking food requires energy. So why we cannot use Cosmic Rays with wavelength of about 0.01 angstrom in microwaves (though they will be cosmic waves oven)? Why we use the Spectrum of higher wavelength?
Microwaves are a compromise between being easy to generate at high powers - so you don't waste energy. Long enough wavelength so it matches typical size food without only heating the surface and short enough that it can be easily shielded.
The precise wavelength was chosen because nothing else used it (at the time) so there were no strict rules on emissions at those frequencies. Unfortunately wifi and bluetooth ended up on the same frequencies for the same reason
The question you may also ask, related to this, is, how would we absorb this cosmic waves to put it into the food. In general, high energy cosmic waves, have two undesirable properties, first they are so ultra-energetic that every normal protein chains or related organic material to life exposed to it is denatured. Secondly, they are very rare and have very small energy density in the low atmosphere.
As about the microwave oven itself, the process of heating food, as long as (normally) most of the food constituent is water, has to do with vibrate the waters molecules by resonance with their "normal" vibration frequency... This water molecules vibrations, heats the food through loosing this energy via friction with other food molecules. (But Im sure you can find more complete answers along this forum, in related topics, as suggested).