Let there be two observables $H,P$ such that there is a twofold degeneracy in all eigenstates, i.e. a full eigenbasis is given by states
$$ \lvert h,p \rangle_1,\lvert h,p\rangle_2$$
with eigenvalues $h,p$ for $H,P$ respectively. The subscript is meant to denote that $\lvert h,p \rangle_1,\lvert h,p\rangle_2$ are linearly independent.
Then there is a third observable $S$ commuting with $H,P$ which can simply be defined as
$$ S\lvert h,p \rangle_1 = \lvert h,p \rangle_1\quad\land\quad S\lvert h,p\rangle_2 = -\lvert h,p\rangle_2$$
since these states form a basis. Since we made all eigenvectors of $H$ and $P$ also be eigenvectors of $S$, $S$ is diagonal in this basis, and the three observables pairwise commute.
Note that the choice of eigenvalue here is completely arbitrary, no one forces us to pick $1,-1$ (but I chose to do so because this anticipates the physical meaning of the observable as helicity, which tells us whether the spin is algined with momentum or not, in this case), the only thing that matters is that the eigenvalues are different.