We do it with helicopters (complete with automated aiming), and we used do it with bombers in WW2, after all.
I’m sure the answer has to do with aerodynamics, and the general rarity of close-range dogfighting in the first place, that make such a design impractical.
It's both aerodynamics and mass. The main guns on most western fighters is the M61 Vulcan which is a 20mm rotary gun. The F-35 mounts a 25mm GAU-12 rotary gun. These are both pretty big guns and are typically mounted internally on the jet. Trying to fit one in a turret would not be practical, it would have tons of drag. In order to be able to rotate and elevate the gun it would need a lot of heavy duty motors to be able to actuate at fighter jet speeds.
Even if such a thing nominally worked, that space and mass could go to missiles. Missiles are far more likely to be used than some gun turret. A bore sight mounted canon is far more useful since the pilot is already going to be pointing the whole plane.
The need for the fighters to have a good aerodynamic. Non-fighters and multi-role fighters have the gun pods.
https://www.weaponsystems.net/system/1049-HH13%20-%20SPPU-22
The 20mm cannon on an F-16 is the entire assembly labeled as items 63, 72, 73 and the ammunition is 78.
How do you envisage this as other than a fixed installation?
It's the square-cube law in action (twice over). Going from a 12.7mm to a 20-25mm bullet... twice the diameter, four times the crosssection, eight times the mass.