Here is a simple approximation to help.
Take a convenient bottle of dry-hopped IPA (or the soft drink of your choice) and drink off half of it. Now pucker up and blow air across the top of the bottle. You will notice this excites an acoustic resonance in the bottle, where the mass of the air entrained in the neck of the bottle bounces off the compliance of the air in the main part of the bottle. The beer bottle "cavity" is resonant at one fundamental frequency, and sound waves at that frequency fill the space surrounding the open end of the bottle.
At microwave frequencies, power is conducted not by currents flowing in a wire but by electromagnetic waves traveling down a hollow square tube, where their wavelength is of order ~the tube width. the tube exhibits a certain amount of microwave capacitance and inductance which depend on the shape of the tube which means you can then fashion yourself a resonant cavity for microwaves, in analogy with the beer bottle cavity resonator described above.
If you then whirl electrons around in a circle past the openings of a series of microwave cavity resonators, it is like blowing air across the top of the beer bottle resonator. The cavity resonators get excited at their fundamental frequency and flood the inside of the magnetron with microwaves of that frequency, which you can then conduct out of the magnetron through another hollow tube.