Let $S$ be the set of restricted permutations of $\{1,2,\ldots,n\}$ where $1$ can be permuted to $1,2$ and $n$ can permuted to $n,n-1$ and $i$ can be permuted to $i-1,i,i+1$ for $2\leq i\leq n-1$.
Let $f:S\to S$ be a bijection. Let $\underbrace{f\circ f\circ \cdots f(x)}_{\text{m times}}=x$ be called the orbit of $x$ under $f$ for some $x\in S$.
I am trying to find a bijection $f$ with an orbit as large as possible. I am not sure how to go about finding that. Any ideas?
Obviously, the best case you can hope for is that $m=|S|$, namely that all permutations in $S$ are in one big orbit. Here is an $f$ which achieves this.
From the comments, you know that a permutation $\pi$ is in $S$ if and only if $S$ the cycle structure of $\pi$ only has fixed points and transpositions, and all transpositions are of the form $(i\;\;i+1)$, switching adjacent elements. For completeness, the proof is this. If $\pi(n)=n$, then by induction, $\pi$ restricted to $\{1,\dots,n-1\}$ also has the form described. If $\pi(n)=n-1$, then you must have $\pi(n-1)=n$, since only $n-1$ and $n$ can map to $n$, and we similarly conclude by induction that $\pi$ restricted to $\{1,\dots,n-2\}$ has the claimed form.
Such a permutation can be uniquely represented as an ordered sequence of ones and twos whose total is $n$. For example, $$ (1\;2)(3)(4)(5\;6)(7\;8)(9)\quad \iff\quad 2,1,1,2,2,1 $$ I will define $f:S\to S$ in terms of these sequences of ones and twos.
More succinctly, $f(s)$ is the next string after $s$ in lexicographic order, unless $s$ is the last in this order, in which case $f(s)$ is the earliest string. Here is an example of the complete orbit when $n=6$.