It is common wisdom that a person who has gone for months or years
without a job is at a disadvantage in the hiring process. Such a gap
in employment dates is considered to be a red flag.
For some jobs it might not matter at all. For others, it clearly does.
I work in software. When I hire, I look for someone who views the role as a profession, and wants to be in it for the long haul. Gaps in the employment history make that harder to project.
If someone has gone for months and years without a job, it makes me wonder if they really want to work now. Perhaps work isn't really important, perhaps it's not necessary, perhaps the applicant just isn't sure. Maybe the work routine won't be to their liking. Perhaps the applicant will get bored and decide to stop working again. Perhaps they will only work long enough to gather money for their next trip around the world - if they did it once, maybe they'll do it again.
For the people I've hired, the strongest predictor of success is their most recent work history. If they are currently performing a very similar job now, then they have a higher chance to slide into this new job and do well. Someone who hasn't worked recently makes for a far riskier hire.
Also, in my industry, things change quickly. Someone who has been out of the workforce for a while is at a disadvantage compared to those who have been living and growing in this profession all along.
It's certainly possible to hire people with gaps in their employment history. I have hired women who wanted to get back into the workforce after being out to take care of their children. But during the interview process, they were clearly at a disadvantage compared to others who didn't have that break in the work timeline. Some have worked out well, others simply did not.