“It works when I run it myself, but not as a service” is one of the most common systemd complaints. The fastest way I know to find out why is to stand where the service stands.
systemd-run --shell (short: -S) starts your shell as a transient service, in your current directory, with its input and output on your terminal. The manual describes it as a shortcut for --pty --same-dir --wait --collect --service-type=exec $SHELL. You get a prompt, but it’s a prompt inside service context: the clean environment systemd gives every service, not the one your login built up.
sudo systemd-run --shell -p User=www-data -p ProtectHome=yes
Inside that shell, try what your service does. env shows how little is set; the manual’s own example of a service environment has little more than PATH and LANG. ls /home shows what ProtectHome= hides. If your script calls a tool that only lives in a directory your profile adds to PATH, you’ll see it fail right here. Type exit and the unit is gone.
The -p options are where it gets useful. Copy the lines from your unit file that you suspect, such as User=, WorkingDirectory= or one of the Protect settings, and add them one at a time until the command breaks. That points straight at the setting that causes it.
The caveat: this shell knows nothing about your real unit. It does not read your .service file or its drop-ins, so anything you don’t pass with -p is simply not there. It needs systemd 240 or newer, which any current distribution has.
Further reading: systemd-run(1) manual page, systemd.exec(5) manual page