Assuming our domain and codomain both have 4 elements, the uniform distribution of inputs to outputs means the function is injective.
You seem to be using the standard technical term ‘uniform distribution’ in a confusing way. Normally the uniform distribution on a finite set $A$ means the probability distribution $P$ with $P(x) = 1/\#A$ for all $x \in A$, where $\#A$ is the number of elements in $A$.
But you haven't mentioned a probability distribution so far; you seem to be abusing the term ‘uniform distribution’ to mean a function $f\colon A \to B$ with the following property: There is a single number $n$ such that for every $y \in B$, the number of elements in the domain mapped to $y$ is $\#f^{-1}(y) = n$. (One might call such a function ‘balanced’, particularly if it's a boolean function—i.e., a function defined on bits whose output is a single bit—but this nomenclature is not standard like ‘uniform distribution’ is in probability theory.)
It is widely agreed that randomly selecting a domain element results in log2(4) = 2 bits of entropy in the selection,
When you say ‘randomly selecting’, that doesn't specify what probability distribution you're randomly selecting by. But if the entropy of the selection is log2(4), then clearly you mean the uniform distribution on the domain. I recommend you specify a distribution whenever you talk about a random selection.
and that because of being injective, the output of said function input this selection will also contain 2 bits of entropy.
Yes, if $f$ is injective then $H[f(X)] = H[X]$ for all random variables $X$ with any probability distribution, including the uniform distribution.
If we double our domain element count to 8, then a random selection will have log2(8) = 3 bits of entropy.
Again, only if the random selection is uniformly distributed over the whole domain.
Because of pigeonhole principle there are collisions, but we defined a uniform distribution, so each of the 4 codomain elements has two domain elements mapped to it.
Yes, if by ‘uniform distribution’ you mean a function that has the same number of preimages $\#f^{-1}(y) \subseteq A$ for any element $y \in B$ in the image.
In the second case, clearly the 3 bits of entropy of the input can't be preserved in the output, but why would fewer than two bits of entropy be preserved? Isn't it still just equiprobably selecting an element from the codomain, given the lack of bias as defined by the uniform distribution of collisions?
Let's take a concrete example.
Define $f(x) = x \bmod 4$ on $\{0,1,2,\dotsc,15\}$. You can easily confirm that $f$ has the property you called ‘uniform distribution’—every element of the image $\{0,1,2,3\}$ has exactly four preimages. That is, under $f$, the following sets of inputs obviously collide:
- $\{0,4,8,12\}$
- $\{1,5,9,13\}$
- $\{2,6,10,14\}$
- $\{3,7,11,15\}$
Consider the following two probability distributions on the domain of $f$:
- $P(x) = 1/4$ for $x \in \{0,1,2,3\}$, and zero otherwise.
- $Q(x) = 1/4$ for $x \in \{0,4,8,12\}$, and zero otherwise.
Clearly $P$ and $Q$ have the same entropy—2 bits. What is the effect of $f$ on the entropy?
Let $X \sim P$. Then $f(X)$ has four possible outcomes each with equal probability 1/4, so the entropy is the same: $H[f(X)] = H[X] = 2\,\mathrm{bits}$.
Let $X \sim Q$. Then $f(X) = 0$ with probability 1. So $H[f(X)] = 0$.
Obviously neither $P$ nor $Q$ is the uniform distribution on the domain of $f$. If we define $U$ to be that distribution—that is, $U(x) = 1/16$ for each $x \in \{0,1,2,\dotsc,15\}$, and draw $X \sim U$—then sure, $H[f(X)] = 2\,\mathrm{bits}$, the maximum possible.