SRAM GX DH 7 Speed on Trek Marlin 5?
Unfortunately your plan will not work.
The compatibility issue is the spacing of the cassette/freewheel sprockets. I'm doubtful that SRAM uses the same spacing as older or cheaper 7 speed drivetrains. (If I were designing for them I'd make the cassette as narrow as possible to allow the drive side hub flange to be moved out for greater wheel strength).
However, even if the sprocket spacing were the same the GX DH 7 derailleur would still shift awfully on your 7 speed freehub because it does not have the ramp and tooth profile design of the GX cassette.
It's a better idea to save your money and purchase a better bike. Trying to put higher end components on cheaper bikes almost always just does not make economic sense.