All polynomial computations are done in $\mathbb{F}_p[x]$.
Case $p \equiv 1, 4 \pmod 5$
First note that $x^4 - 3x^2 + 1 = (x^2-x-1)(x^2+x-1)$
Also note that $1 + x^2 - x^{p-1} - x^{p+1} = (1+x^2)(1-x^{p-1})$,
Using the product rule, $(x(x^2-1)f(x))' = (x^3-x)'f(x) + x(x^2-1)f'(x) = (3x^2-1)f(x)+x(x^2-1)f'(x)$.
If $p \equiv 1, 4 \pmod 5$ then $(1+x^2)(1-x^{p-1}) = (x^2-x-1)(x^2+x-1)(x(x^2-1)f(x))'$.
If $(x^2-x-1)(x^2+x-1)$ divides $(1+x^2)(1-x^{p-1})$ then $g(x) = \frac{(1+x^2)(1-x^{p-1})}{(x^2-x-1)(x^2+x-1)}$ is a polynomial of degree $p-3$ such that $g(x) = (x(x^2-1)f(x))'$.
Since none of the terms of $g$ are of the form $ax^{p-1}$, we can reverse the differentiation to find $x(x^2-1)f(x) = G(x) + H(x^p)$ where $G(x)$ is obtained by converting each term $a_ix^i$ of $g(x)$ into $\frac{a_i}{i+1}x^{i+1}$, and $H$ is an arbitrary polynomial.
We may choose in particular $H = -G$, so that $x(x^2-1)f(x) = G(x) - G(x^p)$.
Note that $g(-x) = g(x)$ so all powers of $x$ in $g(x)$ are even. Then all powers of $x$ in $G(x)$ and $G(x^p)$ are odd. Moreover, $G(0) - G(0^p) = G(1) - G(1^p) = G(-1) - G((-1)^p) = 0$. Hence $x(x^2-1)$ divides $G(x)-G(x^p)$. Therefore $f(x) = \frac{G(x)-G(x^p)}{x(x^2-1)}$ is a polynomial. It is a quotient of two odd functions so $f(x)$ is even.
Therefore, the polynomial $f$ exists if and only if $(x^2-x-1)(x^2+x-1)$ divides $(x^2+1)(x^{p-1}-1)$.
Note that $(x^2-x-1)(x^2+x-1) = x^4 - 3x^2 + 1 = (x^2-4)(x^2+1) + 5$ so $(x^2-x-1)(x^2+x-1)$ is relatively prime to $x^2+1$.
So $f$ exists if and only if $(x^2-x-1)(x^2+x-1)$ divides $x^{p-1}-1$.
By Fermat's little theorem, $x^{p-1} - 1 = \prod\limits_{a\in \mathbb{F}_p^*}(x-a)$.
Hence $f$ exists if and only if all roots of $(x^2-x-1)(x^2+x-1)$ are distinct and in $\mathbb{F}_p$ (so the polynomial splits over $\mathbb{F}_p$). They are automatically distinct because $x^4 - 3x^2 + 1$ has no common roots with its derivative assuming $p \neq 2, 5$.
But the roots of $f$ are $\pm \frac{1\pm\sqrt{5}}{2}$. Let $\varphi = \frac{1 + \sqrt{5}}{2}$. Then the roots are $\varphi, -\varphi, 1 - \varphi, \varphi - 1$. Note that if $p \equiv 1, 4 \pmod 5$ then by quadratic reciprocity, $5$ is a perfect square $\pmod p$ so $\sqrt{5}$ exists in $\mathbb{F}_p$, and $\varphi$ also exists in $\mathbb{F}_p$.
Hence the polynomial $f$ exists for all $p \equiv 1, 4 \pmod 5$.
Case $p \equiv 2, 3 \pmod 5$
Now if $p \equiv 2, 3 \pmod 5$ then by a similar argument as above it is necessary and sufficient for $(x^2-x-1)(x^2+x-1)$ to divide $1 + x^2 - x^{p-1} + 4x^{p+1}$. This occurs if and only if $\varphi$ is a root of the polynomial.
Now $5$ is not a residue $\pmod p$ so $\sqrt{5}$ lies in an extension $\mathbb{F}_p(\sqrt{5})$ of degree 2 over $\mathbb{F}_p$.
Plugging into the polynomial we find $0 = 1 + \varphi^2 - \varphi^{p-1} + 4\varphi^{p+1} = 1 + \varphi^2 + \varphi^{p-1}(4\varphi^2-1) = \varphi + 2 + \varphi^{p-1}(4\varphi+3)$
Using $4\varphi + 3\neq 0$ (since $\varphi \not\in \mathbb{F}_p$) we find $\varphi^{p-1} = -\frac{\varphi + 2}{4\varphi+3} = -\varphi^{-2}$.
So we obtain $\varphi^{p+1} = -1$ or $\varphi^p = 1 - \varphi$.
Expanding we find $\left(\frac{1+\sqrt{5}}{2}\right)^p = \frac{1-\sqrt{5}}{2}$
Using the Freshman's identity $(x+y)^p \equiv x^p + y^p \pmod p$ and Fermat's little theorem $x^p \equiv x \pmod p$ for all $x \in \mathbb{F}_p$ we conclude that $\frac{1}{2}+\frac{5^{(p-1)/2}}{2}\sqrt{5} = \frac{1}{2} - \frac{1}{2}\sqrt{5}$.
This means $5^{(p-1)/2} = -1 \pmod p$, but this is true since the Legendre symbol of $5$ is $-1$ in the case $p \equiv 2, 3 \pmod 5$.
Thus $f$ also exists in that case.
Conclusion
The polynomial $f(x)$ satisfying the properties in the question exists for all primes $p \neq 2, 5$.