Indeed $f(p)= p+1$ cannot be realized by any curve except $\mathbb P^1$ (which I guess is what you meant, since, as Yosemite Sam points out, it can certainly be realized by $\mathbb P^1$).
In fact, if $C$ is a curve such that the number of points of $C$ mod $p$ minus $p$ is bounded, then $C $ is a curve of genus $0$ and has exactly $p+1$ points mod any $p$ where it has good reduction.
You mention Sato-Tate, which could indeed be used to prove this if it was known in suitable generality, but it is nothing more than a conjecture beyond the genus $1$ cases and a little bit of $2$.
Instead, you want to use mod $\ell$ and $\ell$-adic equidistribution, which follows from the Chebotarev density theorem.
Let $C$ be a curve, and suppose the difference between the number of points of $C$ over $\mathbb F_p$ and $p+1$ is bounded by $B$, so in particular is $-B,\dots, B$. For any $n$, the trace of Frobenius on the $\ell^n$-torsion points of the Jacobian of the curve is in $\{-B, \dots, B\}$.
The action of the Galois group on the $\ell^n$-torsion points factors through a finite group, and by Chebotarev, every element of that group arises from a Frobenius, so in fact every element of the Galois group acts on the $\ell^n$-torsion points with trace in $\{-B, \dots, B\}$.
Taking the limit as $n$ goes to $\infty$, every element of the Galois group acts on the $\ell$-adic Tate module with trace in $\{-B, \dots, B\}$, where we use crucially that $\{-B, \dots, B\}$ is closed in the $\ell$-adic topology. In particular, every power of Frobenius has trace bounded by $B$. This implies the eigenvalues of Frobenius on the $\ell$-adic Tate module are roots of unity, which contradicts Weil's Riemann hypothesis for the curve, or, more simply, contradicts the existence of the Weil pairing, unless there are no eigenvalues at all, in which case the genus is $0$, as desired.
You can read about this kind of reasoning in Serre's book $N_X(p)$. A version of this result may even be in there.