I just tried it without :memory: and it dropped me into the SQLite shell without executing the query:
% sqlite3 -cmd '.mode csv' -cmd '.import taxi.csv taxi' \
'SELECT passenger_count, COUNT(*), AVG(total_amount) FROM taxi GROUP BY passenger_count'
SQLite version 3.36.0 2021-06-18 18:58:49
Enter ".help" for usage hints.
sqlite>
Ok, I just went back to see what I did. In fact I echoed a script into sqlite via stdin, not by using `-cmd ''`. In that case, I didn't need to use the :memory: table, and sqlite exited normally when done.