I always read that every maximum likelihood estimator has to be a function of any sufficient statistic. The idea is that, if we are dealing with a random variable $X$ with mass or density function $f(x\mid\theta)$, and $T$ is a sufficient statistic for $\theta$, then by the factorization theorem $f(\vec{x}\mid\theta)=g(T(\vec{x}),\theta)h(\vec{x})$, so maximizing $f(\vec{x}\mid\theta)$ on $\theta$ means maximizing $g(T(\vec{x})\mid\theta)$ on $\theta$, therefore every maximum likelihood estimator for $\theta$ must be a function of $T(\vec{x})$.
However, I have the following counterexample? for this result:
Let $X\sim\text{Unif}(\theta-1/2,\theta+1/2)$. The likelihood function if $L(\theta\mid\vec{x})=1_{[x_{(n)}-1/2,x_{(1)}+1/2]}$, where $x_{(1)}$ and $x_{(n)}$ are, respectively, the minimum and the maximum of our sample $\vec{x}$ of size $n$. Then, any $\hat{\theta}$ with $x_{(n)}-1/2\leq\hat{\theta}\leq x_{(1)}+1/2$ is a maximum likelihood estimator. Also, note that $(X_{(1)},X_{(n)})$ is a sufficient statistic. Now let $$\hat{\theta}=x_{(n)}-1/2+\frac{|x_j|}{1+|x_j|}(x_{(1)}-x_{(n)}+1),$$ where $x_j\neq x_{(1)}$ and $x_j\neq x_{(n)}$. This $\hat{\theta}$ is a maximum likelihood estimator for $\theta$, but is not a function of $(x_{(1)},x_{(n)})$.
What is wrong?