Reckless behavior of psql \e
This has been fixed in v14 as a reaction to this question. The rest of the answer refers to the pre-v14 behavior:
This is (sort of) documented:

If filename is specified, the file is edited; after the editor exits, the file's content is copied into the current query buffer. If no filename is given, the current query buffer is copied to a temporary file which is then edited in the same fashion. Or, if the current query buffer is empty, the most recently executed query is copied to a temporary file and edited in the same fashion.
The new contents of the query buffer are then re-parsed according to the normal rules of psql, treating the whole buffer as a single line.

If you quit the editor without saving, it is the current query buffer or the most recently executed query that are executed.
I agree with you that this is annoying, and you are not the first person I heard complain.
When editing a script, the behavior clearly violates the “principle of least astonishment”:
test=&gt; \! cat q.sql
SELECT 99;

test=&gt; SELECT 42;
 ?column? 
----------
       42
(1 row)

test=&gt; \e q.sql
 ?column? 
----------
       42
(1 row)