Note: Expanded and rephrased, per Todd's question below.
Suppose that we have a set-valued functor $S:\mathcal{C}\to\mathbf{Sets}$, and an arrow $p:Y\to X$ such that $S(p)$ has finite fibers.
From this we can define a second function
$S(Y)\overset{S(p)}{\longrightarrow} S(X)\overset{\mathrm{Card(Y_x)}}{\longrightarrow}\mathbb{N}$
Writing $\mathbb{2}$ and $\mathbb{3}$ for the categories $\{0\to 1\}$ and the walking span $\{0 \to 1 \to 2\}$, respectively, we can think of this as a lifting problem
$\begin{array}{ccc} \mathbb{2} & \xrightarrow{} & \mathcal{C}\\ \downarrow && \downarrow \\ \mathbb{3} & \xrightarrow{} & \mathbf{Sets}\\ \end{array}$
Question 1) What kind of categorical structure is needed in $\mathcal{C}$ (and preserved by $S$) to define a lift from $\mathbb{3}$?
Guess) Assume that $\mathcal{C}$ has a universe or object classifier (as in Todd's comment).
For "nice" doctrines like finite limit categories, every object in a category defines a set-valued evaluation functor on the category of presheaves, and every arrow defines a natural transformation. However, the fiber cardinality of a set-valued functor is not typically preserved by natural transformations.
Question 2 (vague!) ) What leads to this failure of naturality? Is this a typical feature of universe structures? This feels reminiscent of the failure of geometric morphisms to preserve Heyting/dependent product structures; does the answer to (1) depend on that structure? Is there a weaker statement than naturality that continues to hold?
Now suppose that $\mathcal{C}$ contains a commutative monoid object $M$ along with an arrow $v:Y\to M$. We can mimic the construction above by mapping $\mathbb{3}$ to
$S(Y)\overset{S(p)}{\longrightarrow} S(X)\overset{\prod_{Y_x)} v(y)}{\longrightarrow}M$
Cardinality is the special case where $v$ is the constant map $Y \to 1\overset{1}{\to}\mathbb{N}$.
Question 3) What else, if anything, is needed in this case to define a lifting in this case.
References for these and related issues greatly appreciated.