Some are simple, like another planes nearby taking a shot. Those are usually blurry or poorly rendered in the past. As surveillance got better, so did on board and external cameras.
For more "professional" shots, look up Clay Lacy. During peace time or in safe air space, they'd fly low for a nice background and take a whole lot of shots and usually these would be clean and for propaganda or just to showcase a plane for manuals and photo collections.
Upper altitude shots are harder to make but not extremely hard. Like an airborne SR-71. Another SR-71 might be leading the photo target and snap some shots. If it's a low altitude shot, then it's more reasonable to think it's during peace time and set up way in advance to get good shots.Higher up might be commemorative or just spur of the moment.