Speaking in general (from the docker-compose exec docs):
Commands are by default allocating a TTY, so you can use a command such as docker-compose exec web sh to get an interactive prompt.
To disable this behavior, you and JetBrains/PhpStorm devs could use -T flag to disable pseudo-tty allocation when executing the command, i.e.:
docker-compose exec -T web php /path/to/some/file.php
Or set the COMPOSE_INTERACTIVE_NO_CLI environment variable to 1 before running docker-compose exec:
export COMPOSE_INTERACTIVE_NO_CLI=1
In case of PHP Interpreter configuration in PhpStorm (since you do not execute that command yourself), you can set that env variable in the PHP Interpreter settings:

(the screenshot is take from this comment)
Here is PhpStorm ticket to watch after (star/vote/comment) to get notified with any progress: https://youtrack.jetbrains.com/issue/WI-71289
Another option to try:
I updated my docker and switched from using docker-compose to the docker compose plugin (by checking "Use Compose V2" under "Settings/Preferences | Build, Execution, Deployment | Docker | Tools"), and now it works, so it might be a docker-compose specific problem.
COMPOSE_INTERACTIVE_NO_CLI=1