Executing a command as a nologin user
One way is to launch a shell for that user (explicitly specifying the shell):
sudo -u www-data bash
This will launch a (bash) shell as the specified user. You can then execute your command(s) and logout (to return to your previous shell)
As root you can use
su -s /bin/sh $user — the
-s option overrides the configured shell for the user.