How is the recoil momentum distributed or countered for smaller aircraft or drones while using a mounted gun? Is there any hydraulic mechanism to counter it and how it is distributed across the entire body of an aircraft?
In case of combat aircraft, the guns are hard mounted on the fuselage (or wings, for that matter) so that the recoil force is distributed throughout the body. In this case, the large aircraft mass acts to reduce the effects, though if the gun has too much recoil, it can cause damage to the aircraft. For example,
The MiG-27's GSh-6-30 cannon didn't prove particularly useful in practice. It was an impressive weapon in principle, ..., but the recoil -- about 5.5 tonnes (6.05 tons) -- still had a tendency to inflict damage on the aircraft. ... Landing lights almost always broke after firing,
In case of smaller aircraft or drones, you can chose a gun with lesser recoil. Or the drone (for example) could be programmed to fly back to its original position as a way of 'absorbing' the recoil.
Another way is to mount the gun on stabilization platform, which makes sense only if the gun is quite small. A few such systems exist, which usually use robotic stabilizers to reduce the effects of the recoil due to the gun.
The force of the recoil is distributed into the airframe in the same way that engine thrust is. Recoil is nothing but impulse thrust, like what happens inside a piston engine which is exploding gas propelling a piston mass as well.
So structurally, there is no special wizardry required, everything just needs to be strong enough. The main issue here is making sure that the aircraft can still be flown while the gun is doing its job, and that the aircraft is still pointed more or less in the intended direction, as this answer addresses.
The firing of a forward firing cannon can generate thousands of pounds of reverse thrust. The use of shock absorbers in the gun mounting has the effect of reducing the peak recoil forces which might damage the airframe, but it does not reduce the average recoil force/thrust or the total impulse imparted to the aircraft over the time the gun is firing.
If the weapon aiming system in a drone or UCAV is capable of improved accuracy relative to a manned aircraft then a high rate of fire might be rendered unnecessary, which would reduce the impact on the aircraft's flight performance and would also mean that the gun itself could be lighter for a given calibre.