How to run wall command as another user in Linux (RHEL8)

This is because wall uses getlogin() to find the name of the user.

if (!(whom = getlogin()) || !*whom)
            whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???";
        if (!whom) {
            whom = "someone";
            warn(_("cannot get passwd uid"));
        }

And then:

snprintf(lbuf, line_max,
                _("Broadcast message from %s@%s (%s) (%s):"),
                whom, hostname, where, date);

From the getlogin man page:

getlogin() returns a pointer to a string containing the name of the user logged in on the controlling terminal of the process, or a NULL pointer if this information cannot be determined.

...

These functions let your program identify positively the user who is running (cuserid()) or the user who logged in this session (getlogin()). (These can differ when set-user-ID programs are involved.)