This explanation works for entry-level candidates but fails to explain why senior candidates are often expected to do similar exercises _in addition to_ any work experience they have.
New lawyers, doctors, and CPAs have to demonstrate textbook mastery to pass a handful of exams once in their career. Engineers are expected to demonstrate textbook mastery for every job they apply to _for their entire career_ (and often multiple times per application!)
everyone you mentioned here has some kind of an ongoing public tally going on - Yelp/Google reviews, customer referrals that lead to new business or lack thereof. If I'm looking at a crappy lawyer or accountant, they probably have a 2* average of public reviews and/or out of business because noone wants to refer to them. Is there an equivalent of that for a mid-career programmer?
I don't think this is true. Most of the doctors and lawyers I know work at big firms with a publicly reviewable presence, but there's no practical way to review individuals at those firms.
New lawyers, doctors, and CPAs have to demonstrate textbook mastery to pass a handful of exams once in their career. Engineers are expected to demonstrate textbook mastery for every job they apply to _for their entire career_ (and often multiple times per application!)