We have a classical reversible circuit $U$ implementing a classical boolean function $f: \left\{0, 1\right\}^n \to \left\{0, 1\right\}$, which also takes some $a$ ancilla bits, and has side effect of outputting garbage $g(x)$. Then we have the following circuit diagram for uncomputing the garbage.
The trick is to CNOT the answer qubit (which I'll call the 2nd qubit) $f(x)$ with a fresh ancilla (the 1st qubit) initialized to $|0\rangle$, which changes the state of the first qubit to $f(x)$. Then we use the inverse of the circuit and get back $|x\rangle$ and other ancilla qubits back to $|0\rangle$.
If we are using this circuit with classical inputs, then it is clear that $f(x) \in \left\{0, 1\right\}$. Then, $f(x)$ CNOT $0$ is the same as taking the XOR of the two bits.
If we feed the input a uniform superposition of all the inputs, then we want the circuit to behave as follows: $$\frac{1}{\sqrt{2^n}}\sum_{x \in \left\{0,1\right\}^n} |x\rangle \otimes |0\rangle^{\otimes a+1} \mapsto \frac{1}{\sqrt{2^n}}\sum_{x \in \left\{0,1^n \right\}} |x\rangle \otimes |f(x)\rangle \otimes |0\rangle^{\otimes a}.$$
Now this is the part I don't understand. In the quantum case, $|f(x)\rangle$ can be a general quantum state $a|0\rangle + b|1\rangle$, and CNOT has the effect of entangling the first qubit with the second one, such that the joint state of the two qubits is now $a |00\rangle + b|11\rangle$. Now, $U^{-1}$ undoes everything done inside $U$, but it does not undo the CNOT between the first two bits. Therefore, after everything, the first two qubits should still be entangled, right? In that case, why can we write each term in the output as $|x\rangle \otimes |f(x)\rangle$, which indicates that they are not entangled.