From your log (which was actually the terminal session, which contains far less information than the actual .log file):
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
LaTeX2e <2020-02-02> patch level 5
which tells you you have TeX Live 2020 from February, and also
subcaption.sty 2020/01/22 v1.3d Sub-captions (AR)
caption.sty 2020/01/03 v3.4h Customizing captions (AR)
caption3.sty 2020/01/03 v1.8h caption3 kernel (AR)
which are also from the beginning of the year.
The problem is that that version of caption.sty defines \caption \AtBeginDocument, which then happens after your command-line redefinition. You can either update (recommended) or use a later hook to redefine \caption.
To update TeXLive you only need to run (maybe with sudo if you installed with root):
tlmgr update --all --self
(--all tells it to update all packages; you can replace it by a list of packages to update; use tlmgr update --list to see packages that have update candidates. --self tells tlmgr to update itself if needed). In your particular case, for some reason sudo tlmgr doesn't work, so you can try changing the ownership of the texlive folder with sudo chown -R $(whoami):$(whoami) /usr/local/texlive ($(whoami) expands to your user name).
To work around that you need to use a hook later than \AtBeginDocument (unless you had a newer LaTeX, then you could use lthooks and all would be much easier).
The best way would be to add a \csname mycommandline\endcsname after \begin{document}, then build with:
$ pdflatex "\def\mycommandline{\def\caption##1{}} \input{test.tex}"
However, assuming you don't want to change your document (I do not recommend doing this!) you can use \AfterEndPreamble, provided by etoolbox, but since you are loading from the command line you can't load a package, otherwise TeX sets \jobname (opens the .log) and your document will be saved into texput.pdf. So you need a hook to delay loading etoolbox to delay redefining \caption (see the complication?). You can hook into \documentclass (don't):
pdflatex "\edef\documentclass{\unexpanded{\RequirePackage{etoolbox}\AfterEndPreamble{\def\caption#1{}}}\unexpanded\expandafter{\documentclass}} \input{test.tex}"
pdflatex "\listfiles\DebugHooksOn\AtBeginDocument{\def\caption#1{}} \nonstopmode \input{test.tex}"then upload the log to https://pastebin.com/ (or similar), please – Phelype Oleinik Feb 15 '21 at 22:20tlmgr update --self --allshould update your texlive (possibly needingsudodepending how it was installed) – David Carlisle Feb 15 '21 at 22:45lthooksbecause I assumed your TL was up-to-date (it's not). As David said, updating should solve the problem. The culprit is that your version ofcaptiondelays defining\captionto\AtBeginDocument, which happens after your redefinition. If you don't want to update you can (but I really don't recommend you to) build withpdflatex "\edef\documentclass{\unexpanded{\RequirePackage{etoolbox}\AfterEndPreamble{\def\caption#1{}}}\unexpanded\expandafter{\documentclass}} \nonstopmode \input{test.tex}"– Phelype Oleinik Feb 15 '21 at 23:10\AfterEndPreamblesolution doesn't work. I'm trying to update my texlive... but neither the solution withsudonor the one without sudo work: https://pastebin.com/nQmMD8Zm (I never updated my texlive versions) – Gabriele Feb 15 '21 at 23:12sudo chown -R $(whoami):$(whoami) /usr/local/texlive, thentlmgr update --self --allagain – Phelype Oleinik Feb 15 '21 at 23:17