Variables do not work in InDesign, but you can work around this by using media queries.
In the documentation table (Doc), InDesign is not explicitly listed (only Photoshop and XD are), but the feature does work.
@media (prefers-color-scheme: dark) {
…
}
@media (prefers-color-scheme: darkest) {
…
}
@media (prefers-color-scheme: light) {
…
}
@media (prefers-color-scheme: lightest) {
…
}
Hope this helps.