Let me first prove that $f(n) = n^2 + O(n)$, then give a heuristic why $f(n) = n^2$ for big enough $n$ (which maybe could be made into an actual proof with enough perseverance) and then explain why I find the problem statement slightly unnatural, and what I think should be the right version.
For the first, note that most of the lines have the form $(\cdot, x, y)$, $(x, \cdot, y)$ or $(x, y, \cdot)$, and there are $3n^2$ such lines, and the number of remaining lines is $O(n)$ ($6n+4$ if my math is correct). To exlude all these lines consider $\{0, \ldots , n-1\}$ as $\mathbb{Z}/n\mathbb{Z}$, and consider the set of points $(x, y, x+y)$ (there are $n^2$ points in it). Note that it intersects each of the aformentioned lines, and for each of the remaining $O(n)$ lines we can pick remove one point on it for a total of $n^2+O(n)$ points.
For the second, although my construction of the set intersecting main lines may appear to be quite rigid, in fact there is a whole lot of such sets, so it is very foreseeable that we can pick these $n^2$ points in such a way that we cover all the extra lines as well by chance, if $n$ is big enough. If we went one dimension down (from $3$ to $2$), then the sets covering main lines correspond to permutations, and we just have to cover 2 diagonals, which is doable if $n\ge 3$, I expect similar to be possible in dimension $3$ (and all higher dimensions, as long as $n$ is big enough).
The above, in particular my construction of the intersecting set, suggests that we should consider points not lying in $\mathbb{R}^3$, but really in $(\mathbb{Z}/n\mathbb{Z})^3$, and then consider lines in this space, that is we should allow lines to "wrap around" the sides of the cube. Then I expect the answer to actually be $n^3-(n-1)^3$, and at least in the case $n$ being prime I imagine it being provable with some version of the combinatorial Nullstellensatz.