Of course. Never thought of that. It's probably OK on small cubs and the like as the low output combined with the large mass of the magneto would provide sufficient cooling.
On larger bikes they would have to provide slots for additional air flow and that would bring the problem of water in the electrics in the rain or when washing.

On some knock-off cub engines there are problems with water penetration into the magneto chamber, as the maker didn't bother to fit a gasket to the outer casing...

Sometimes things are difficult to believe and our limited knowledge can't accept them. An example is the fuel pumps on some cars that live inside the fuel tank, submerged, and the fuel actually runs through the rotor, commutator, etc with no ill effect and no explosions...