The short answer: if you want to learn languages like COBOL or Fortran, do it, but do it for FUN, not for some idea of eventual profit or job security.

The long rambling answer:

I've been joking that a high paying consultancy in COBOL is my eventual retirement plan for most of my life. Like most good jokes, its built on some kernels of truth.

One kernel of truth is that I've never shied away from touching and working on "legacy code" no matter what the language. In the corporate environments that have been the majority of my career I've been asked to touch all sorts of strange things. As many point out here and many will keep pointing out, the ability to learn or dive into programming language N+1 starts to get easier the more programming languages you already know, the more you can see the similarities and understand some of the major family trees. Showcasing those skills has been a valuable resource in several jobs, having the willingness to touch some of the legacy stinky apps has been a way to signal maturity and technical competence. It's helped boost my path to seniority in some of the companies I've worked at.

It has not been job security. Knowing the deep arcane knowledge of a company's "mission critical" legacy systems doesn't make you immune to layoffs. Companies know that you picked it up quickly, the next "sucker" may pick it up just as quickly.

Another kernel of truth in the joke is part of the "retirement job" part in that it is not the job I want next, it is the job I expect last. The more I've worked on legacy apps the less I want to work on legacy apps. I've always known that legacy apps are legacy for a reason. They aren't fun to work on. They aren't exciting things to put on your resume. If you have legacy languages and efforts on your resume that doesn't necessarily help you get the next job. Companies almost always have lofty ideas that "we'll eventually rewrite the legacy app in something modern and cool". Companies hire for "modern and cool" even when what they are actually looking for is "willing to touch old legacy cruft". Making the "COBOL is my retirement plan" joke in an interview has been the way to keep the legacy cruft out of my resume to leave more room for "modern and cool", but also signal "yes, I've done the legacy stuff, I expect to keep doing the legacy stuff".

An easily overlooked kernel of truth in the "retirement job" part is that I learned early on that you hear a lot about "there's very few people doing this job so they are highly paid" and found out that the "causal arrows" in these stories is a lot more confusing in real life. True legacy jobs like COBOL mainframe programmer aren't just high-paying because few people take or want to take those jobs, they are high-paying because few of those jobs exist. Those jobs aren't just packed by highly senior engineers where senior also means aged and near-retirement; those highest paying jobs are sometimes by their very nature the sinecures and endgames and "rewards" for high seniority developers in a company. In many cases you do literally retire into those jobs. They are "mission critical" enough to be worth paying high salaries to high senior engineers to keep working on them, but they are siloed enough and "slow enough" that they don't actually have a lot of work left to do other than just to have someone on call for the small bug fix or percussive maintenance. Companies know those can be sweet jobs to reward decades of loyalty, or luck of the draw. Companies know those can be jobs to dangle for someone to climb the ladder all the way up staying in individual contributor roles. So they are, in a lot of cases they are.

So to recap: it isn't really a path to job security, it isn't necessarily a path to get hired, and it isn't the path to high-paying jobs that it sounds like, because it isn't an "immediate path", especially not for someone fresh into the industry.

But all of that said, learn every programming language you can and have fun with it. The more languages you know the better a leg up you have to learning the next language. If you want to spend time today learning COBOL or Fortran, do it because it is fun, not because you expect it to pay off. Learning COBOL is surprisingly easy. It's a relative of BASIC in ways that aren't immediately obvious (in both directions of the family tree). Fortran isn't just legacy code, if you dig deep enough into Python data engineering you'll find that some of the underpinning code is new Fortran code in the 2020s. It's got the easy "foreign function interface"/cross-language binding of classic C, but is a language that's always been tuned for high performance math. ("FORmula TRANslation", it's name has always signaled it was a language designed first and foremost for math.) Learning Fortran in the context of a Python is a fun excuse to learn two or three languages in symbiosis.

Prolog is considered a "legacy" language but can be a lot of fun to explore and can be a bit mind-breaking because it uses logic programming in ways that few other programming languages do.

Common Lisp is considered a "legacy" language and has a lot of fun things to teach, like some of the earliest ideas of functional programming and cool ideas like code is data is code. Lots of languages have descended from Common Lisp on one branch or another, things you learn in Common Lisp have modern needs.

Smalltalk is considered a "legacy" language and is a fun way to explore early ideas in "Object-Oriented Programming" and "Actor-Oriented Programming" from their deepest, oldest source.

Javascript is both a "legacy" language and a living language and there's no end to what you can learn from it and its ecosystem.

There's all sorts of weird and fun languages in niches smaller or rarer than "legacy" languages, too. You can learn a lot from weird things like Inform 7 and Io and Lua and Elixir and whatever else you might stumble on here on Hacker News or embedded in your favorite game/game engine/game platform.

Learn everything that seems fun, and that will serve your career well. It will associate learning new languages as a fun activity that you enjoy doing, even if eventually it will be some job telling you you need to learn some old ugly thing for some "mission critical" app no one else really wants to touch. Hopefully some of the "fun" rubs off and you feel a little bit less miserable about the ugly dark cave in the hidden depths of some corporate structure they want you to do that in.