Tries from Richard Fussell, Craig Warlow, Ceri Sweeney, Jamie Ringer and Ian Gough gave the Dragons a commanding 25-3 lead at Rodney Parade.
The Dragons then relaxed and converted tries Yann Fior and Romain Teulet brought Castres to within eight points with four minute remaining.
But the home side managed to rally and Warlow's penalty made the game safe.
The bonus-point win ensured the Dragons leapfrogged Castres to finish third in Pool Three behind winner's Munster and runner's up Sale, who both qualify for the quarter-finals.
Dragons coach Paul Turner:
"The Heineken Cup is a great competition to be in. We didn't like being called 'punchbags' which is something someone said about us last week. "A lot of our hard work was frittered away. We keep winning these games 27-19 or 28-17 when there is a chance to close these games out, but I thought the youngsters did us proud out there."
Dragons: Tuipulotu; Fussell, A. Thomas, Sweeney, Breeze; Warlow, Cooper; Black, S. Jones, R. Thomas, Gough, Sidoli, Ringer, Forster, Owen.
Replacements: Maddocks for Black (71), Brown for S. Jones (44), Oakley for Owen (78).
Not used: Robinson, Hall, Baber, Hinton.
Castres: Christophers; Fior, Montoro, Tuilagi, Fleming; Teulet, Barrau; Hoeft, Roumieu, Castex; Ghezal, Spanghero (capt), Bernad, Taussac, Faure.
Replacements: Capo Ortega for Hoeft (71), Nallet for Ghezal (66).
Not used: Vigneaux, Puricelli, Albouy, Milford, Raffault.
Att: 4,475
Referee: Malcolm Changleng (Scotland)