As originally reported in quarto-dev/quarto-cli#4603, HTML-based gt tables with a heading (i.e., those produced through tab_header()) produce invalid HTML (two <thead> elements) which is understandably not parsed correctly by Pandoc (though browsers are okay with this markup).
To solve this, there should only be a single <thead> element. So, the heading (if present) should reside in the same element as the column labels (if they are to be displayed). The CSS classes will move to the child <tr> elements. This needs to be tested well to avoid any major regressions.