Catalysis of the reaction: (S)-2,3,4,5-tetrahydropyridine-2,6-dicarboxylate + NAD(P)+ + H2O = (2S,4S)-4-hydroxy-2,3,4,5-tetrahydrodipicolinate + NAD(P)H + H+.
2,3,4,5-tetrahydrodipicolinate:NAD(P)+ oxidoreductase activity