Clean/reduce static in electret microphone caused by "dirty" Raspberry Pi pin output voltage
The first step in eliminating noise is to identify the source. I think you did a good identifying the noise source in this example. If the static does not exist when you use the battery but does exist when you you the Pi's +3.3V and ground, then the noise is from the Pi's power pins (which is pretty common). Think about it as noise on both the + and - supply, not just the ground. You want DC,  but are getting DC plus lots of static noise, so you can get rid of that by putting a capacitor from the positive voltage supply to ground. A common thing your see people do is put a 10 uF in parallel to a 100 nF between V+ and ground to take advantage of specific non-ideal capacitor behavior.
That should help clean up your supply voltage. Something else to look into is the problem is still there is an audio transformer. That will isolate the ground of the Pi from the ground of the audio input. That helps if there is a &quot;ground loop&quot; that acts like a radio antenna. However, that noise usually sounds like a hum, not static.
Edit: in above, every time I say &quot;ground&quot; I mean the negative supply or ground - they are the same thing in my description above.