While mortars are not suited for aircraft as weapons, some engineers have looked at doing things like adapting mortar bombs as improvised aircraft bombs. This would have to involve removing the normal fuse mechanism and replacing it with a regular bomb fuse. Like most explosive ordinance used by firearms, a mortar bomb needs to be carried safely by the crew, and not detonate inside the barrel when fired. Various mechanisms are used (depending on the mortar), but generally include safety pins when carried and "setback" mechanisms which are activated by the acceleration of the round in the barrel. Aircraft bombs are generally armed and fused by different mechanisms, including barometers, radar and even "windmill" fuses which spin when the bomb is released into the airstream.
This is a lot of work for what in reality is a relatively small explosive weapon. Only forces with no real military aircraft at all, or militaries which are using very small aircraft would even consider this a feasible plan, considering there are much more effective purpose built weapons available.

A Hellfire is a much more effective purpose built weapon
One possibility which might work in some alt history version of WWII could be a variation of the Rheinmetall SG 117. This was a recoilless multi barrel weapon mounted at more or less right angles to the axis of flight, with the idea the aircraft would fly under a bomber and a photocell triggered a salvo of rounds upwards into the enemy airplane. Similar devices were also developed with 7 or 21 barrels.

Rheinmetall SG 116
For a ground attack aircraft, turning the weapon around and triggering the cannon to fire downwards as you overfly a target at high speed would have a similar effect, but 30mm high velocity cannon shells, even with an explosive filler would have limited effect on most military hardware or troops under cover. Expanding the device to fire a salvo of 81mm mortar shells instead would have a much greater impact on the target, and with WWII era aircraft and anti aircraft defences, this might actually be worth investigating.
Of course, to carry a useful battery of 81mm recoilless tubes sized to fire 81mm mortar shells would require a much larger plane than a fighter, we would need a medium bomber at least. In the modern world, a fast overflight of an enemy target is just asking to be shot down. In Afghanistan, I never saw aircraft or even helicopters releasing ordinance, they were multiple kilometres away and using guided munitions. Large and relatively slow aircraft making ground attack runs like contact patrol fighters are a thing of the past (even A-10's use long range missiles for the most part), and AC-130's only come out at night and against enemies with limited or no air defense capabilities.