Assuming the monitor and cables are known good, I would suspect one of two things.
First, I would try some contact cleaner in the VGA port, in case there’s dirt/gunk/etc in there preventing good contact. It’s simple enough, and no disassembly required.
After that, I would suspect maybe some cracked solder joints on the VGA port. Not a simple fix, but it should be fairly obvious, once you disassemble things to check. Probably not worth risking a repair if you’re not confident in your soldering skills. I’d personally just leave it alone if it has no other issues, unless you really need video out for some reason.
Beyond that, I’m not sure bad caps would only affect mirrored external video. I’m no expert on iMac video, but is there really anything that needs to be done beyond sending the same signal to the VGA port? I would assume straight pass through since it’s just external mirroring and not dual displays, right?