Cost, reliability and simplicity! A WWII-era 20-40mm cannon upgraded with automated targeting system doesn't even have to accurately hit the target if its shell explodes into a cloud of metal fragments that hits propellers and control surfaces or gets ingested into a jet engine.
Directed energy weapons are still in their early days, they're not powerful enough to just shrug off all sorts of potential countermeasures the way a solid chunk of metal hitting the target does.