Consider a measurable function $f \colon X \to Y$, where $X$ and $Y$ are measurable spaces. The following definition makes sense even with no measurable structure, but the main question does not.
Consider the sets $A$ that satisfy the following condition. The sets those where the function $f$ is injective with respect to the entire domain $X$: $$ \forall x_a \in A \; \forall x \in X \text{ we have } f(x_a) = f(x) \implies x= x_a. $$ In particular, this is a stronger condition than only requiring $f|_A$ to be injective, as $f$ may not take the values it takes in $A$ outside of $A$, either.
Call such a set a good set. Based on blackboard sketches it seems that an equivalent definition for a set to be good is that, for all subsets $S \subseteq A$, we have $f^{-1}(f(S)) = S$.
Unions of good sets are still good sets, so there is a maximal good set.
Question: Is the maximal good set measurable? What about if $X = Y = \mathbb{R}$ (with Borel or Lebesgue measure, for example)? Blackboard sketching suggests that there is some hope for continuous real-valued functions.
Also, if this kind of set of injectivity has a standard name or work done on it, then I would be happy to know of it.
The maximal good set certainly isn't measurable in general. For instance, if the $\sigma$-algebra on $Y$ is $\{\emptyset,Y\}$, then any function is measurable, regardless of the $\sigma$-algebra on $X$.
I don't know what happens for the nice case of Borel functions on $\mathbb{R}$. The maximal good set is always coanalytic, since it is the complement of the projection of the Borel set $\{(x,y):f(x)=f(y),x\neq y\}\subset\mathbb{R}^2$ (onto either coordinate).