Yes there is such a function.
Define integers z(m,n) as follows iteratively as follows:
z(m,1) is the mth non-prime number (z(1,1)=1, z(2,1)=4, z(3,1)=6, ...)
z(m,n+1) is the z(m,n)'th prime
Define f by f(z(2m+1,k))=z(2m+2,k) and
Theorem: For every positive integer n, there exists a,b such that
Suppose not. Then there is a smallest positive integer n which fails to
be of this form.
Then either n is prime, in which case it is the tth prime for some
1<=t<n. Then t=z(a,b) for some a,b, and hence n=z(a,b+1), which is a
Or n is non-prime, in which case it is the tth non-prime for some
1<=t<=n, whence n=z(t,1).
Corollary: For all integers n, f(f(n)) is the nth prime
n=z(a,b). Either a is even, in which case f(n)=z(a-1,b+1) and f(f(n))=z(a,b+1)=nth
prime, or a is odd, in which case f(n)=z(a+1,b) and f(f(n))=z(a,b+1)=nth