I have a much simplier shortcut (just ot test something):
wait 20 seconds
play music
And it also doesn't work when iphone is locked.
As suggested by Claude31 I allowed all kind of accesses to the lock screen and it still doesn't work.
Device used: iPhone SE (2nd gen), iOS 17.3.1