That is why, at least years ago, all of the airlines had a cooperative arrangement to allow any pilot to ride free, to encourage them to be on planes as passengers, in case something of the sort occurred. I don’t know what the policy is now, but of course it makes sense for somebody with the requisite skill set to replace the pilot who fell ill. This honestly should not have been news, it should only have been news if it was found that the guy didn’t go into the cockpit.
It is called professional courtesy. The cockpit jumpseat belongs to the captain. Provided someone has legal access to the cockpit the captain can permit them to hitch a ride. The captain always has the final say.
Jumpseat access has been the focus of various labor and merger disputes over the past 50 years. Being reciprocal means that most airlines play nice with each others’ pilots.
Since many airline pilots commute to their flying assignments jumpseat access is an important privilege in the airline industry.