I did further playing around, and I now realize the intent. The following is my findings, in case someone else stumbles upon this topic.
The formula in question was:
=IF(B6="Category",
QUERY(Q:AD,"SELECT "®EXEXTRACT(ADDRESS(1, COLUMN(Q:Q)), "[A-Z]+")&",' ', "®EXEXTRACT(ADDRESS(1, COLUMN(T:T)), "[A-Z]+")&","®EXEXTRACT(ADDRESS(1, COLUMN(U:U)), "[A-Z]+")&","®EXEXTRACT(ADDRESS(1, COLUMN(S:S)), "[A-Z]+")&","®EXEXTRACT(ADDRESS(1, COLUMN(Z:Z)), "[A-Z]+")&","®EXEXTRACT(ADDRESS(1, COLUMN(AA:AA)), "[A-Z]+")&
" WHERE "®EXEXTRACT(ADDRESS(1, COLUMN(AD:AD)), "[A-Z]+")&"=FALSE AND "&char(64+COLUMN(Q:Q))&" IS NOT NULL AND "&char(64+COLUMN(V:V))&" !='Hide' ORDER BY "&O8&O19),
IF(B7="Category","Reset Sort By in B6",
QUERY(AF:AL,"SELECT "®EXEXTRACT(ADDRESS(1, COLUMN(AF:AF)), "[A-Z]+")&"
,' ',"®EXEXTRACT(ADDRESS(1, COLUMN(AG:AG)), "[A-Z]+")&",' ',"®EXEXTRACT(ADDRESS(1, COLUMN(AJ:AJ)), "[A-Z]+")&","®EXEXTRACT(ADDRESS(1, COLUMN(AH:AH)), "[A-Z]+")&","®EXEXTRACT(ADDRESS(1, COLUMN(AK:AK)), "[A-Z]+")&
" WHERE "®EXEXTRACT(ADDRESS(1, COLUMN(AL:AL)), "[A-Z]+")&"=FALSE AND "®EXEXTRACT(ADDRESS(1, COLUMN(AF:AF)), "[A-Z]+")&" IS NOT NULL ORDER BY "&O10&O19&" LABEL ' ' ''")))
(Note that I added line breaks to improve readability) and the intent of the “REGEXTRACT(ADDDRESS…” construct was to make the Query formula (which has to be in text) robust to subsequent column insertions and deletions. But there are less verbose ways to do this, as discussed in the article Take advantage of Custom Arrays in Google Sheets and its follow-on comments.
Final thought/lesson learned: The YTD template is quite old; I suppose this is the disadvantage of using older templates as starting point: they were often built before people got more experienced with Sheets and/or Sheets functionality was augmented.