  Magic state distillation and the Shor factoring algorithm make essential use
of logical diagonal gates. We introduce a method of synthesizing CSS codes that
realize a target logical diagonal gate at some level $l$ in the Clifford
hierarchy. The method combines three basic operations: concatenation, removal
of $Z$-stabilizers, and addition of $X$-stabilizers. It explicitly tracks the
logical gate induced by a diagonal physical gate that preserves a CSS code. The
first step is concatenation, where the input is a CSS code and a physical
diagonal gate at level $l$ inducing a logical diagonal gate at the same level.
The output is a new code for which a physical diagonal gate at level $l+1$
induces the original logical gate. The next step is judicious removal of
$Z$-stabilizers to increase the level of the induced logical operator. We
identify three ways of climbing the logical Clifford hierarchy from level $l$
to level $l+1$, each built on a recursive relation on the Pauli coefficients of
the induced logical operators. Removal of $Z$-stabilizers may reduce distance,
and the purpose of the third basic operation, addition of $X$-stabilizers, is
to compensate for such losses. For the coherent noise model, we describe how to
switch between computation and storage of intermediate results in a
decoherence-free subspace by simply applying Pauli $X$ matrices. The approach
to logical gate synthesis taken in prior work focuses on the code states, and
results in sufficient conditions for a CSS code to be fixed by a transversal
$Z$-rotation. In contrast, we derive necessary and sufficient conditions by
analyzing the action of a transversal diagonal gate on the stabilizer group
that determines the code. The power of our approach is demonstrated by two
proofs of concept: the $[[2^{l+1}-2,2,2]]$ triorthogonal code family, and the
$[[2^m,\binom{m}{r},2^{\min\{r,m-r\}}]]$ quantum Reed-Muller code family.
