The behavior you are requesting of bspwm is counter-intuitive to this rule you specifically wrote. Nonetheless, if VS Code popup windows have a different instance name, you could have a script running in the background which checks instance name of any new window and execute the command bspc desktop -f last
when a VS Code popup appears.
If the instance name is the same for VS Code main app and its popup windows, you may listen to the state of VS Code windows (using bspc subscribe; see the manpage) and execute the previous command on VS Code floating windows (because popups will be floating).
For example, apply this to all VS Code windows:
while bspc subscribe -c 1 node_focus node_state > /dev/null; do
bspc query -N -n "focused.floating" | while read -r wid; do
bspc desktop -n $wid -f last
done
For your second question, if I understand correctly you're trying to have a given workspace moving to your external monitor when available and returning to your primary monitor if no other monitor is connected. You can look at the archwiki to learn how to setup bspwm for multi monitors.
Using the same if conditions as explained in this wiki you could also have for example a rule bspc rule -a Code follow=on desktop='^4'
when only one monitor is connected, and bspc rule -a Code follow=on desktop='^7'
when an external monitor is connected (and workspace 7 will be defined to be shown on your external monitor).