You need screws that reach into the 2x4s behind the trim pieces. With luck, slightly thicker, slightly longer screws will do the job for you.

I have a hollow bathroom door with hinge problems. Unfortunately, longer/thicker screws won't work because there are large nails in the 2x4s where the hinge screws need to be. So I'll eventually have to remove the trim and work on the 2x4s (removing the big nails in the way, repairing the 2x4s and refastening it somehow...)

HTH a bit. Good luck.

Cheers,
Scott.