I get what you mean. Your APFS-encrypted drive won't ask you for entering the password to unlock it. It skips this step to automatically mount the drive at the time when you log into your Mac right?
This is similar to my APFS-encrypted external hard drive that doesn't ask for a password when connected to Mac. This issue is most probably caused by that you've saved the password in the keychain. To put it more bluntly, you've checked the box next to "Remember this password in my keychain" on a previous pop-up that asks for a password.
To make the pop-up asking for a password to unlock the APFS-encrypted volume appear again, you don't need to execute a script. You just need to remove the password for unlocking the APFS-encrypted volume from Keychain Access.
- Open Launchpad > Other > Keychain Access.
- Enter the disk name of your APFS-encrypted drive into the upper search box on the Keychain Access window.
- Check if your APFS-encrypted drive is listed there. If it is, right-click on it and choose "Delete" to prevent the keychain from saving the password for unlocking the disk.