Then how does the oracle shutdown work during server shutdown when the shutdown script is run as root?
root can su without supplying a password so the general technique in boot/shutdown scripts is
su <appropriate user name> <service/daemon control command>
In the case of oracle, the oracle user's login customisation is required to set envars so "su -" is used and the general command becomes
su - $ORA_OWNR -c <some oracle command>
This is illustrated in the many sample oracle boot/shutdown scripts posted on the net, for example here