The problem isn't using flight as part of the solution, the problem is the attitude of "Most of the time flight is a resource. Using up a resource is a valid reason to have the challenge.".
That attitude isn't a problem. It's impossible to plan for every contingency and that's before the players come to mess things up. Using your examples: you have to assume you have a flying race in the party, or an artificer, or that the DM gave out
winged boots or another flying magic item. If none of those are true, then who cares? You get your encounter.
And what if one of those is true? Well, there are still ways to deal with it. There's guards with bows or flying creatures that are hunting or territorial. Or you can take some of ground-based hazards and reskin it as an aerial hazard. For instance, quicksand: use the rules for it, but reskin it so it's actually a powerful wind vortex that either sucks a character somewhere dangerous or "drowns" them in wind so powerful that they can't breathe.
Depending on the type of challenge, you could simply say that flying isn't the way to get it. For instance: a shrine to a god of strength or something similar is on top of a pillar of stone. Only someone who
free climbs the tower using only their own strength can get the blessing of the god; flying, teleporting, using a
spider climb, even just using ropes to help you ascend, is cheating.
And let's say that it's some minor thing--the players need to get from A to B, and a cliff or chasm is in the way. OK, let them fly. This isn't an encounter, it's flavor text used to breathe some life into their journey. No biggie.
You
could ask to make Str or Dex checks or something (because of high winds or rocky protrusions or angry but otherwise mundane birds they have to dodge around, etc.), and on a bad roll, they drop some supplies. They could either waste time going back down to retrieve the supplies (while dealing with whatever is on the ground), or they could press on--and if there's a time crunch, this could be a dilemma.