Why some Huffman codes have efficiency better than others?
First off, though the codes you gave are what the Huffman coding process produces, they aren't the only possible prefix codes for those two cases of sources.

For example, imagine if you used the code $\{\texttt{00}, \texttt{01}, \texttt{10}, \texttt{11}\}$ - then the average length is $2$ and the efficiencies drop to $82.5\%$ (case 1) and $87.5\%$ (case 2).

What the Huffman coding process guarantees is the most efficient prefix code possible for a given source, not a perfectly efficient code for every source.

So your question really is "why is it possible with some sources to make 100% efficient Huffman codes, and with other sources the most efficient possible Huffman code is less than 100% efficient?"

The answer there is that if you have a perfectly efficient Huffman code, then it's impossible to tell the difference between a stream of (source -> Huffman code) and a stream of uniformly random $\texttt{0}$s and $\texttt{1}$s. In your case number 2, with the first Huffman code, you have that situation: a stream of the source encoded by the Huffman code begins with $\texttt{0}$ half the time, and with $\texttt{1}$ half the time. When it starts with $\texttt{0}$, you start a new character from the source and so the next digit naturally is also evenly distributed. When it starts with $\texttt{1}$, half the time the next digit is $\texttt{0}$, half the time $\texttt{1}$, etc. This property (that after any sequence of bits, the chance of the next bit being $\texttt{0}$ or $\texttt{1}$ is $\frac{1}{2}$) means that the resulting binary stream has an entropy of 1 bit of entropy per output bit. (The same as a random binary source)

However, in case 1, (again using the first Huffman code) after seeing a $\texttt{1}$ in the stream, you're more likely to see a $\texttt{0}$ than a $\texttt{1}$. This means that the binary stream you get by connecting your source to the Huffman code has an entropy of less than 1 bit of entropy per output bit. (and therefore, that the binary stream is carrying less information per output bit than a random binary source)

The perfect match in case 2 happens because the probabilities of the source are all (negative) powers of $2$ and the probability of each output symbol matches the probability that a uniformly random noise source would output the symbol's Huffman string. Basically, the maximum possible efficiency for a Huffman code is a measure of how well a source's output probabilities can be approximated in binary.

Note that if we took your case 1 source and considered outputs two at a time, we'd be able to better approximate the probabilities in binary, and therefore get a more efficient Huffman code:

$$
\begin{array}{|c|l|l|}
\hline
\mathrm{output}&amp; p &amp; \mathrm{Huffman}\,\mathrm{code} \\ \hline
a_0a_0 &amp; 0.25 &amp; \texttt{10} \\ \hline
a_0a_1 &amp; 0.15 &amp; \texttt{000} \\ \hline
a_0a_2 &amp; 0.075 &amp; \texttt{0100} \\ \hline
a_0a_3 &amp; 0.025 &amp; \texttt{01110} \\ \hline
a_1a_0 &amp; 0.15 &amp; \texttt{001} \\ \hline
a_1a_1 &amp; 0.09 &amp; \texttt{110} \\ \hline
a_1a_2 &amp; 0.045 &amp; \texttt{1110} \\ \hline
a_1a_3 &amp; 0.015 &amp; \texttt{011010} \\ \hline
a_2a_0 &amp; 0.075 &amp; \texttt{0101} \\ \hline
a_2a_1 &amp; 0.045 &amp; \texttt{1111} \\ \hline
a_2a_2 &amp; 0.0225 &amp; \texttt{011000} \\ \hline
a_2a_3 &amp; 0.0075 &amp; \texttt{0110011} \\ \hline
a_3a_0 &amp; 0.025 &amp; \texttt{01111} \\ \hline
a_3a_1 &amp; 0.015 &amp; \texttt{011011} \\ \hline
a_3a_2 &amp; 0.0075 &amp; \texttt{01100100} \\ \hline
a_3a_3 &amp; 0.0025 &amp; \texttt{01100101} \\ \hline
\end{array}
$$

This has an average code length of $3.3275$, whereas the double-output source has an entropy of $3.30$ for an efficiency of $99.04\%$.

If you continued this process to 3 symbols at a time, you'd be able to get a $99.24\%$ efficient code. To 4 symbols, $99.43\%$ efficient.