In order to perform universal fault-tolerant quantum computation, one needs to implement a logical non-Clifford gate. Consequently, it is important to understand codes that implement such gates transversally. In this paper, we adopt an algebraic approach to characterize all stabilizer codes for which transversal T and T† gates preserve the codespace. Our Heisenberg perspective reduces this question to a finite geometry problem that translates to the design of certain classical codes. We prove three corollaries of this result: (a) For any non-degenerate [n, k, d] stabilizer code supporting a physical transversal T (which might not be logical T), there exists an [n, k, d]] CSS code with the same property; (b) Triorthogonal codes form the most general family of CSS codes that realize logical transversal T via physical transversal T; (c) Triorthogonality is necessary for physical transversal T on a CSS code to realize the logical identity. The main tool we use is a recent characterization of a particular family of diagonal gates in the Clifford hierarchy that are efficiently described by symmetric matrices over rings of integers [N. Rengaswamy et al., Phys. Rev. A 100, 022304]. We refer to these operations as Quadratic Form Diagonal (QFD) gates. Our framework generalizes all existing stabilizer code constructions that realize logical gates via transversal T. We provide several examples of codes and briefly discuss connections to decreasing monomial codes, pin codes, generalized triorthogonality and quasitransversality. We partially extend these results towards characterizing all stabilizer codes that support transversal π/2ℓ Z-rotations. In particular, using Ax's theorem on residue weights of polynomials, we provide an alternate characterization of logical gates induced by transversal π/2ℓ Z-rotations on a family of quantum Reed-Muller codes. We also briefly discuss a general approach to analyze QFD gates that might lead to a characterization of all stabilizer codes that support any given physical transversal 1- or 2-local diagonal gate.