I believe it already exists on Android starting from version 7 (not sure). By default, if the phone is locked, you need to enter your code to turn it off; otherwise, it's not possible. If it's not locked, of course, it turns off, which makes sense.
Best regards
jojo3549
Posted messages85StatusMember35
I have Android 8 (Honor 7x) and it doesn't ask for a code to turn off (completely) the phone.
In any case, it is possible to bypass this software function Read this.