For example, if gpg is used as part of a script executed from a window manager (e.g. passmenu or rofi-pass) the $TERM variable may not be set due to the window manager not being executed from within a shell (e.g. started from a display manager like LightDM). This should still allow us to access the GUI pinentry dialog.
When running gpg/gpg-agent without $TERM:
$ gpgconf --kill gpg-agent $ echo | TERM= gpg --clearsign -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 gpg: signing failed: IPC syntax error gpg: [stdin]: clear-sign failed: IPC syntax error
Running gpg/gpg-agent with $TERM:
$ gpgconf --kill gpg-agent $ echo | TERM=xterm gpg --clearsign -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 [opens pinentry dialog as expected]