> XTerm OSC 4 may have a very limited ability to probe the color palette. At least on `st` I can only see default foreground, background and cursor colors, not the full 16-color palette. This mostly just amplifies the point elsethread by @hnlmorg.
What st version? For me, 0.9.2 prints the entire color cube with
for n in `seq 0 255`; do printf '\033]4;%d;?\033\\' "$n"; done; read
(although unsurprisingly, it's subtly broken: I sent ST, but the
responses are terminated with BEL...)