Let's think of this in very simple terms. Initially operating under the assumption that a coin is fair, if we flip it $n$ times, there is still a probability of $1/2^n$ that it lands all heads, and $1/2^n$ that it lands all tails, purely by random chance. For example, for $n = 5$ flips, you could get such extreme results as often as $1$ in $16$ such experiments!
So with such a few number of flips, there is no test you could perform to give you $95\%$ confidence that the coin is not fair if in fact it is not fair, because the most discriminating rejection criterion that all flips must be heads or all flips must be tails, cannot with such few flips, tell you with better than a $100(1 - \frac{1}{16})\% = 93\%$ confidence that the coin is in fact not fair.
This does, however, suggest that $n = 6$ might work. In this case, your test to determine unfairness is again that all outcomes are the same (all heads, or all tails), but here the probability of this event is $(1/2)^6 + (1/2)^6 = (1/2)^5 = 1/32$, and such a test has at most a probability of $0.03125$ of being wrong about a fair coin: that is to say, you don't know if the coin is fair or not; but if the coin were fair, and you flipped it six times and got all heads, or all tails--purely by random chance--and as a result concluded it was unfair, such a fluke could happen only $3.125\%$ of the time.
Consequently, the confidence level of such a test is $100(1-0.03125)\% = 96.875\%$. So we need to flip a coin at least six times to be at least $95\%$ confident.
It is worth mentioning that five flips isn't good enough, but six flips puts us over $95\%$ confidence. This is because of the discrete nature of the binomial distribution. We could get closer to an actual confidence of $95\%$ if we were willing to flip the coin more times and relax the test criteria. For example, suppose you were to flip the coin $n = 17$ times, and you would call the coin unfair if you do not observe at least $5$ heads and $5$ tails. This test would have a confidence level of $100(1-\frac{1607}{32768})\% = 95.0958\%$. But of course, such a test requires more effort--$17$ flips instead of $6$.