Most of these variables are intended for the dynamic linker, or other components of the C library, and it’s the dynamic linker which takes care of removing them when starting setuid binaries. This is documented in the “ENVIRONMENT” section of
man ld.so (for the GNU C library):
For security reasons, if the dynamic linker determines that a
binary should be run in secure-execution mode, the effects of
some environment variables are voided or modified, and
furthermore those environment variables are stripped from the
environment, so that the program does not even see the
definitions. Some of these environment variables affect the
operation of the dynamic linker itself, and are described below.
Other environment variables treated in this way include:
ld.so-affecting variables are documented individually:
This variable is ignored in secure-execution mode.
appears in the documentation for each such variable.
The full list can also be seen in the GNU C library’s source code, as can the removal code itself, both for dynamically-linked binaries and for dynamic linking in statically-linked binaries.
Other C libraries’ dynamic linkers behave in a similar fashion, for variables which they care about; for example, musl documents that
This variable is completely ignored in programs invoked setuid, setgid, or with other elevated capabilities.
for a number of variables (
MUSL_LOCPATH), and that some features of the
TZ variable aren’t available in such circumstances.