You can tell altair to resolve the color scales seperately:
a1 = (alt.Chart(df.filter(pl.col('class')=="A"))
.mark_bar()
.encode(x='x', y='y', color=alt.Color('y', scale=alt.Scale(scheme="greens"))))
a2 = (alt.Chart(df.filter(pl.col('class')=="B"))
.mark_bar()
.encode(x='x', y='y', color=alt.Color('y', scale=alt.Scale(scheme="oranges"))))
(a1 | a2).resolve_scale(color="independent")
More info in the docs.