This question already has an answer here:
As technology is advancing, could robots take over pilots' jobs? If so, how might they accomplish this?
It's already in the works. Fully autonomous unmanned combat air vehicles are no less than 10 years away. I'd say that the major airlines will follow in 10-15 years, most likely starting with the elimination of the First Officer with fully automated functions. Similar systems will be introduced, and most likely before the airlines on corporate jets.
It will be fought tooth and nail by the pilot unions, but sooner or later the algorithms these AI pilots use will become increasingly sophisticated to the point that there will be another incident similar to that faced by US Airways 1549 where an AI is under control and makes a decision saving the crew and passengers where 97% of all human pilots who, when faced with an analogous situation, failed resulting in a catastrophic accident. Thus public confidence will be bolstered in these systems and public opinion will sway in their favor - even demanding these systems will be on board. All that's required at that point is flights operated by AI are 40% more efficient and 63% more likely to be on time without interruptions of service due to weather, crew fatigue, etc. At that point the first experimental, totally unmanned commercial flights will happen, probably after the corporate jets lead the way.
Military wise a similar thing is bound to happen as ACM algorithms improve, making super maneuverable drones which are capable of defeating Red Flag instructor pilots 97% of the time and more and more years of confidence built on the AI systems both in peacetime exercises and in conflicts will finally eliminate the manned fighters and bombers.
Perhaps the last vestiges of manned flying will be in general aviation and remote bush flying for commercial reasons (the revenge of GA?), but even these will slowly be eliminated as AI controlled aircraft and infrastructure capable of allowing off field landings and takeoffs, even in the most remote or difficult places come online.