When org-scan-tags runs in a batch mode invocation, the value of the variable comment-start-skip is nil even while scanning an org file. The function org-scan-tags calls (org-agenda-skip), which in turn calls (looking-at comment-start-skip). Since the value of comment-start-skip is nil, it triggers the error (wrong-type-argument stringp nil). To fix this, the function org-agenda-skip should ensure that the variable comment-start-skip is set to the appropriate value.
Two comments: 1. The issue was not present in Org version 9.4.4. The issue comes up when I build my webpage using Emacs 28.1 and Org 9.5.2, but not when I build it using Emacs 27.2 and Org 9.4.4. 2. The issue can indeed be fixed, e.g., by changing the source of org-agenda-skip to invoke (org-mode) immediately before the let statement. Doing this presumably sets the variable comment-start-skip to the expected value, and the invocation succeeds. Emacs : GNU Emacs 28.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33, cairo version 1.17.6) of 2022-04-27 Package: Org mode version 9.5.2 (release_9.5.2-25-gaf6f12 @ /usr/share/emacs/28.1/lisp/org/)