Let $X$ denote a finite set, and $q:X \rightarrow \mathbb{R}$ denote a function. Then $$\sum_{x \in X}q(x) \in \mathbb{R}.$$ Now suppose we have a function $f : X \rightarrow Y$. Then we can use $f$ to break up the above sum as follows:
$$\sum_{x \in X}q(x) \overset{*}{=} \sum_{x \in X, y \in Y, y = f(x)} q(x) = \sum_{y \in Y}\sum_{x \in X, y = f(x)} q(x) = \sum_{y \in Y} \sum_{x \in f^{-1}(y)} q(x)$$
Seems legit, but to be honest, I don't really understand the $\overset{*}{=}$ step at a purely logical level; all I can say about it is: "Its obvious!"
So define $\Phi = (x \in X)$ and $\Psi = (x \in X \wedge y \in Y \wedge y=f(x))$. It would be nice if it were true that: $$(*)\qquad \forall x\forall y(\Phi \iff \Psi),$$ but that just isn't true.
Question. If not $(*)$, then what relationship between $\Phi$ and $\Psi$ allows us to deduce $$\sum_{\Phi} q(x) = \sum_{\Psi} q(x),$$
and why does it work?
Please don't remove the abstract algebra tag; the above question makes sense for $\mathbb{R}$ replaced by an arbitrary commutative monoid, and I'd like to see what that community has to say about the issue.