How to grant an app root access without GUI interaction?
android.permission.ACCESS_SUPERUSER was defined by SuperSU but:


  Due to changes in Android 5.0 Lollipop, this permission has been deprecated and is completely ignored from SuperSU v2.30 onwards


Also only app which declares a permission in its AndroidManifest.xml file can be granted that permission. Shell (com.android.shell) is an AOSP's dummy app to define UID for adbd, it must not have any such third party permission in its Manifest.

Magisk doesn't use this or any other such permission at all. So you have to grant the permission through user interface. Or try to modify database or configuration file directly where permission preferences are stored. In case of Magisk it's sqlite3 database (/data/adb/magisk.db):

~# sqlite3 /data/adb/magisk.db .tables
hidelist  logs      policies  settings  strings
~# sqlite3 /data/adb/magisk.db '.mode column' '.headers on' 'select * from policies'
uid         package_name  policy      until       logging     notification
----------  ------------  ----------  ----------  ----------  ------------
10146       com.termux    2           0           1           1    
~# sqlite3 /data/adb/magisk.db "INSERT INTO policies (uid,package_name,policy,until,logging,notification) VALUES(2000,'com.android.shell',2,0,1,1)"
~# sqlite3 /data/adb/magisk.db '.mode column' '.headers on' 'select * from policies'
uid         package_name  policy      until       logging     notification
----------  ------------  ----------  ----------  ----------  ------------
10146       com.termux    2           0           1           1           
2000        com.android.  2           0           1           1           
~# sqlite3 /data/adb/magisk.db 'DELETE FROM policies WHERE uid = 2000'



For help on SQLite: sqlite.org
Above commands are working at the moment but Magisk may change database location, table names, table structures etc. any time.
Values may possibly be cached in running processes. So your changes may get ignored or overwritten. In that case putting a modified database from recovery (with proper permissions) may work. I didn't try though.