when they say flat frequency response with headphones they mean relatively flat not completely.
like if you compare the frequency response graphs of a pair of sennheiser hd600's to like a generic sony pair you'll see that the sennheisers are much much more even than the sony's.
other things are just as important though. some headphones have a poorly designed frame that might rattle with the bass frequencies or even they can just be bad at handling higher volumes and can have distortion.
You should definitely first research the frequency responses of the headphones you are about to purchase but also always make sure you give them a listen.
A lot of factors can change the way they sound regardless of the frequency response like the ear cup design. I've found ones that go completely over your ears like around them with no cushions pushing up against your ears terrible. the reverb must bounce around inside them too much or something. I've heard good things about open back ones. I'm thinking about buying a pair of those.
It sucks though because you used to be able to find a great relatively flat pair for like 60 bucks. Now I find all of the accurate ones are like 200-400 :/
I used to love sony for cheap prices on good phones but the newest ones seem to have a bit of a peak at around 800 hz which would be a major problem for me.
make sure you physically look up the graphs and don't trust what the brand's site's tell you. the page for the kns 8400's claims a flat frequency response for example but they have a unreasonably huge boost at around 100 hz and down. that might be fine if you can get away with putting the cutoff for you highpass over 100hz but when you're working with stuff like double bass like me that's a huge problem because 100 hz is where a lot of issues arise and getting the highpass perfect is essential there. plus i gotta cut off at around 45 hz so that would be a huge problem.
anyways, the reason why a flat frequency response is important to begin with is because for example if your bass is boosted in your headphones, then when you do your mixdown you're going to make your bass too low since your headphones are telling you it's louder than it is.
all in all monitors are better but we all can't afford them or sometimes we're in a situation like an apartment where you can't make too much noise so there's all sorts of reasons to prefer headphones.
I do wonder though what would be better... monitors in a room with parallel walls, no sound proofing, no bass traps, etc versus a good pair of headphones.
I'm willing to bet headphones would be better than monitors in a bad space for phase amplification and all of that. would be really interesting to see someone do a comparison on that anyways.
one more note: as much as most of us dislike ear buds since they tend to be tinny and too geared towards the high end... they are great for high end monitoring for the same reason we usually don't like them. like before doing spectral repairs, clicks, pops, crackles etc are all way easier to hear in ear buds so it's good to have a pair for that stuff handy.