I have a bag like that. The steel supporting chains at the top are there for good reason. And I don't think even a short 2x4 would hold it up very long once you start pounding away at it. Beyond that, closet doors are fitted in inside walls and don't require headers in some jurisdictions.
The rigidity of a piece of wood, as a beam, is proportional to its width and proportional to the 4th power of its height. So using a 4x4 will only double the kind of strength you want. You would be better to use, say, a 2x10 or whatever you can fit inside the closet, assuming I understand you correctly. Now your problem is that this beam will have a tendency to bend in the middle along its length or topple. So you will need some framing to make it stay upright.
It's not just the static weight of the bag. It's the fact that hitting it will put a lot of weight in motion. Come to think of it, can you be sure that the framing around the closet door can stand up to this? Perhaps you should think of building a frame to support the big beam inside the closet door so that that bag won't distort the door frame?