Q:

Functions of random variables and conditional probability

Suppose I have two random variables $X,Y$ over some finite set and a function $f$ such that
$\forall z \in Image(f) \,  Prob[f(X,Y)=z | X = x] = Prob[f(X,Y) = z]$
Intuitively, I would think that if I now consider the function $h(X,Y) = g(f(X,Y))$ I should have
$\forall w \in Image(h)\, Prob[h(X,Y) = w | X = x] = Prob[h(X,Y) = w].$
However, a simple counterexample shows this is not the case. If we choose $X,Y$ to be uniformly distributed over $\{0,1\}$ and 
$$f(X,Y) = (-1)^{X+Y}$$
then $f(X,Y)$ and $f(X,Y) | X = x$ both have the same distribution: they are uniformly distributed over $\{-1,1\}.$
However, if I take $g(z) = log_{-1}(z)$, then $h(X,Y) = g(f(X,Y)) = X + Y$ does not have the same distribution as $X + Y | X = x$. For example, we have that  $Prob(X+Y=2) = 1/4$, but $Prob(X+Y = 2 | X = 0) = 0.$
What is going on in this counter-example that breaks the intuition? Is it that $\log_{-1}(z)$ is not a well-defined function (it has multiple complex branches)?  Is it because $\log_{-1}(z)$ is discontinuous for $z = -1$? Or is the intuition just not true?

A:

The "intuitive" claim in the beginning is correct:
\begin{equation}
P(h(X,Y) = w \mid X = x) = P(f(X,Y) \in \{z \mid g(z)=w\} \mid X = x) \\ = \sum_{z_i \in \{z \mid g(z)=w\}} P(f(X,Y) = z_i \mid X=x) = \sum_{z_i \in \{z \mid g(z)=w\}} P(f(X,Y) = z_i) = P(f(X,Y) \in \{z \mid g(z)=w\}) = P(h(X,Y) = w).
\end{equation}
An alternative way of stating it would be that if $f(X,Y)$ and $X$ are independent, then $g(f(X,Y))$ and $X$ are independent. Applying a deterministic mapping to one of independent random variables cannot lose independence.
The counterexample does not work since there is no function $g$ with the property that $g((-1)^{(X+Y)})=X+Y$ for all values  $X+Y$ may attain here (as @whuber pointed out in the comments). The example is equivalent to your first try (mentioned in comments) with $f(X,Y)=X+Y~\mathrm{mod}~2$ upto relabeling the range of $f$. As you found that there was no function in that case the first version, there is no applicable function in the new case, either.
$\mathrm{log}_{-1}$ not being such a function could be interpreted as being due to it having 'multiple branches': if we want $(-1)^w = z$ to imply $\mathrm{log}_{-1}(z)=w$,  $\mathrm{log}_{-1}(1)$ should equal both $0$ and $2$, which is a proof-by-contradiction for nonexistence of such a function. We may decide to define if as a multivalued function or perhaps define a function  of $(X,Y)$ that picks the correct "branch" based on $X+Y$ -- but then the premises of the initial claim do not hold. 

