I'd say "the frame" is the right choice, but some people might call it "the molding." "The door frame" and "the window frame" are common expressions in the US.
"When closed" is ambiguous. Do you mean it bangs when someone closes it? (Most doors do that when you "slam" them.) Or do you mean when the door has been closed for a period of time, it makes a banging sound without anyo