I have done some more research about this question and here is my (partial) conclusion.

The theorem as I stated it in the body of the question seems to be wrong because it's too general. What is true is essentially just what is proved in the paper of [Lehmann and Scheffé] linked by Iosif Pinelis (where they get a possibly non-measurable $\phi$), and the obvious corollary for that can be obtained from it for the measurable case, which I state below.

If a set function $S:\mathcal{X}\to E$ satisfies condition $(\star)$, and if we endow $E$ with the final $\sigma$-algebra $\mathscr{E}$ ($A\in \mathscr{E}$ if and only if $S^{-1}(A)\in\mathscr{X}$), then $S:(\mathcal{X},\mathscr{X})\to (E,\mathscr{E})$ is a measurable sufficient statistic which is "measurably minimal" in the class of all measurable sufficient statistics $T$ with the final $\sigma$-algebra on the codomain, that is $S=\phi(T)$ for some measurable $\phi$.

So, after consulting some of the main references in the field ([1], [2], [3]) I got convinced that - surprisingly - the right way of thinking of minimal sufficient statistics is in terms of set functions, not of measurable functions, and if instead we insist on stating the theorem in terms of measurable functions, the right form is the one above. I haven't found anything about the general case where the codomains are endowed with an arbitrary $\sigma$-algebra, and I can just suppose that in this case the result fails (I am not sure). I also suppose that maybe it is also due to this lack of measurability of minimal sufficient statistics that the concept of minimal sufficient $\sigma$-algebra was created, which is similar but not equivalent (see [Landers and Rogge]).

[Lehmann and Scheffé]:https://www.jstor.org/stable/25048038
[1]:https://www.jstor.org/stable/25048038
[2]:https://projecteuclid.org/journals/annals-of-mathematical-statistics/volume-25/issue-3/Sufficiency-and-Statistical-Decision-Functions/10.1214/aoms/1177728715.full
[3]:https://projecteuclid.org/journals/annals-of-mathematical-statistics/volume-20/issue-2/Application-of-the-Radon-Nikodym-Theorem-to-the-Theory-of/10.1214/aoms/1177730032.full
[Landers and Rogge]:https://projecteuclid.org/journals/annals-of-mathematical-statistics/volume-43/issue-6/Minimal-Sufficient-%7csigma-Fields-and-Minimal-Sufficient-Statistics-Two-Counterexamples/10.1214/aoms/1177690882.full