We prove a theorem unifying three results from combinatorial homological and commutative algebra, characterizing the Koszul property for incidence algebras of posets and affine semigroup rings, and characterizing linear resolutions of squarefree monomial ideals. The characterization in the graded setting is via the Cohen-Macaulay property of certain posets or simplicial complexes, and in the mo...