I happened to find a possible solution for this problem, if a user uses
systemd.
It seems that your use case is with elogind, so, this solution may not
work directly, but it would help seeking the way to solve.
In my system, I identified that:
The initial command creating /run/user/$UID/gnupg is this one (for
systemd users) by running gpgconf command:
/lib/systemd/user-environment-generators/90gpg-agent
And then, this script also invokes gpgconf command:
/etc/X11/Xsession.d/90gpg-agent
To introduce keeping old behavior of sockdir, I needed something
which runs before 90gpg-agent.
So, I created the file:
/etc/systemd/user-environment-generators/89-gpg-keep-old-behavior-of-sockdir-under-home
with the content of:
==========================
#!/bin/sh
D=/run/user/$(id -u)/
CONFIG_FILE=$HOME/.keep-old-behavior-of-gpg-sockdir
# Make a file to prevent use socketdir under /run by gnupg, but keep
# old behavior using $HOME/.gnupg
if [ -e $CONFIG_FILE ]; then
touch ${D}/gnupg
fi
==========================
That is, when a user specified by the file of
$HOME/.keep-old-behavior-of-gpg-sockdir, it creates a file
'/run/user/$UID/gnupg' before the creation of directory
/run/user/$UID/gnupg, so that the directory cannot be created and used.
Then, by the fallback mechanism of GnuPG, $HOME/.gnupg will be used.