I think the answer is: $$f(n)=n+2 \;\;\;\;\;\;\; \mathrm{for} \; n \geq 3.$$
This can be proved by induction.
Since the OP has already established that $f(3)=5$ and $f(4)=6$. The statement is true for $n=3$ and $n=4$.
We need only prove that if the statement is true for $n=k$, then it is true for $n=k+2.$
For simplicity, let us see how to prove that if $f(4)=6$, then $f(6)=8$. The general case is just the same.
Let us fill up the smallest and the largest sets, i.e. $A_1$ and $A_6$ first.
So we may let $$A_1=\{ 1\}$$
and $$A_{6}=\{ 2, 3, \cdots, 7\}.$$
$$$$
Next we consider $A_2$ to $A_5$.
Obviously each $A_i$ must contain at least one element other than $1, 2, \cdots, 7$. We must introduce at least one more element, say $8$.
Therefore at least $8=6+2$ elements are needed.
To see that the addition of $8$ is enough, we may reason as follows:
First assign $8$ to each each $A_i, \; i=2, 3,4, 5$. Thus
$A_2 = \{8, x \}$, $A_3 = \{8, x, x \}$, $A_4 = \{8, x, x, x \}$, $A_5= \{8, x, x, x, x\}$.
where the $x$'s are elements to be filled in.
We may also write it as follows:
$$A_2=\{8 \}\cup B_1, A_3=\{8 \}\cup B_2, A_4=\{8 \}\cup B_3 \; \mathrm{and \; A_5=\{8 \}\cup B_4}$$
where $|B_i|=i$ and $B_i \not\subset B_j$ whenever $i \neq j.$
Thus to fill up $B_2$ to $B_5$ is just the same question asked with $n=4.$
Can we fill up $B_2$ to $B_5$ by using the elements of $\{2, 3, 4, 5, 6, 7\}$ so that no extra element is
needed?
The answer is yes. This is because $f(4)=6$ and there are exactly $6$ elements in $\{2, 3, 4, 5, 6, 7\}$.
For concreteness, we may let
$$B_1=\{ 2\}, B_2=\{3, 4\}, B_3=\{3, 5, 6 \} \; \mathrm{and} \; B_4=\{4, 5, 6, 7 \}$$
and finally obtain
$$A_1=\{1\}, A_2=\{8, 2\}, A_3=\{8, 3, 4\}, A_4=\{8, 3, 5, 6 \}, A_5=\{8, 4, 5, 6, 7 \} \; \mathrm{and} \; A_6=\{2, 3, 4, 5, 6, 7 \}$$
Thus we have proved that $f(6)=8$ if $f(4)=6$.
Same arguments obviously apply for all $n$.
Therefore if the statement is true for $n=k$, then it is true for $n=k+2.$
By the principle of mathematical induction,
$$f(n)=n+2 \;\;\;\;\;\;\; \mathrm{for} \; n \geq 3.$$
Best Answer
Suppose that there are $n$ such sets $A_1,A_2,\ldots,A_n$, represented by indicator vectors $\mathbf{a}_1,\mathbf{a}_2,\ldots,\mathbf{a}_n\in\mathbb{F}_2^n$. Equip $\mathbb{F}_2^n$ with the usual inner product $\langle\_,\_\rangle$.
We already know that the vectors $\mathbf{a}_1,\mathbf{a}_2,\ldots,\mathbf{a}_n$ are linearly independent. Therefore, they span $\mathbb{F}_2^n$. Thus, the vector $\boldsymbol{1}:=(1,1,\ldots,1)$ can be written as $$\mathbf{a}_{j_1}+\mathbf{a}_{j_2}+\ldots+\mathbf{a}_{j_k}$$ for some $j_1,j_2,\ldots,j_k\in\{1,2,\ldots,n\}=:[n]$ with $j_1<j_2<\ldots<j_k$. If $k<n$, then there exists $r\in[n]$ such that $r\neq j_\mu$ for all $\mu=1,2,\ldots,k$. That is, $$1=\langle \mathbf{a}_r,\boldsymbol{1}\rangle =\sum_{\mu=1}^k\,\langle \mathbf{a}_{j_\mu},\mathbf{a}_r\rangle=0\,,$$ which is a contradiction. Therefore, $k=n$, whence $$\boldsymbol{1}=\sum_{j=1}^n\,\mathbf{a}_j\,.\tag{*}$$ Consequently, each element of $[n]$ belongs in an odd number of $A_1,A_2,\ldots,A_n$, whence at least one of the sets $A_1,A_2,\ldots,A_n$.
Furthermore, it is not difficult to show that every element of $[n]$ must belong in at least two of the $A_i$'s. (If there exists an element of $[n]$ belonging in exactly one $A_j$, then you can show that there are at most $n-2$ possible $A_i$'s.) Let $d_j$ be the number of sets $A_i$ such that $j\in A_i$. Then $$\sum_{j=1}^n\,d_j=3n\,.\tag{#}$$
Note that $d_j\geq 2$ for all $j\in[n]$.
From (*), we conclude that $d_j\geq 3$ for every $j\in[n]$. However, (#) implies that $d_j=3$ for all $j\in[n]$; i.e., every element of $[n]$ must be in exactly three of the $A_i$'s. Write $\mathbf{e}_1,\mathbf{e}_2,\ldots,\mathbf{e}_n$ for the standard basis vectors of $\mathbb{F}^n_2$. We see that $$\mathbf{e}_j=\mathbf{a}_p+\mathbf{a}_q+\mathbf{a}_r$$ where $j$ is in $A_p$, $A_q$, and $A_r$. This shows that $$A_p=\{j,x,y\}\,,\,\,A_q=\{j,y,z\}\,,\text{ and }A_r=\{j,z,x\}$$ for some $x,y,z\in[n]$. Since $x$ already belongs in $A_p$ and $A_r$, it must be belong in another $A_s$. Clearly, $A_s$ must be equal to $\{x,y,z\}$. From here, we conclude that the four elements $j,x,y,z$ belong in exactly four of the $A_i$'s, which are $\{j,x,y\},\{j,y,z\},\{j,z,x\},\{x,y,z\}$. The rest is easy.