I know there this question has been answered, but I am interested by what is wrong with this solution.
Question: What is the probability of getting three consecutive heads in 5 tosses?
Solution: Let $H_i$ be the event of heads on the $i$-th toss. We are interested in the probability of $A_1 = H_1H_2H_3$, $A_2 = H_2H_3H_4$, $A_3 = H_3H_4H_5$.
$\begin{equation} \begin{split} P(A_1\cup A_2\cup A_3) &= P(A_1) + P(A_2) + P(A_3) \\&\quad - P(A_1\cap A_2) - P(A_1 \cap A_3) - P(A_2 \cap A_3) + P(A_1 \cap A_2 \cap A_3) \\ &= \cfrac{1}{8} + \cfrac{1}{8}+ \cfrac{1}{8} - \cfrac{1}{4} - \cfrac{1}{4} - \cfrac{1}{2} + \cfrac{1}{2} \\ &= - \cfrac{1}{4} \end{split} \end{equation}$
Your approach and formula for $P(A_1\cup A_2\cup A_3)$ are fine,
but, as pointed out in comments, some of your calculations were erroneous.
$P(A_1\cap A_2)=P(H_1H_2H_3H_4)=\dfrac1{16}$;
$P(A_1\cap A_3)=P(H_1H_2H_3H_4H_5)=\dfrac1{32}$;
$P(A_2\cap A_3)=P(H_2H_3H_4H_5)=\dfrac1{16}$;
and $P(A_1\cap A_2\cap A_3)=P(H_1H_2H_3H_4H_5)=\dfrac1{32}$.
Therefore $P(A_1\cup A_2\cup A_3)=\dfrac18+\dfrac18+\dfrac18-\dfrac1{16}-\dfrac1{32}-\dfrac1{16}+\dfrac1{32}=\dfrac14.$
Of the $32$ possible outcomes for five tosses, the following $8$ have three consecutive heads:
TTHHH, THHHT, THHHH, HTHHH, HHHTT, HHHTH, HHHHT, HHHHH.