Can you "extend" a drywall stud?
The best way to handle this situation is to span two studs at the end of the closet with a smallish plank, screwing it into both studs. Then you can screw the rod end mount to that plank and rest assured that it's as sturdy as you can get it.

The "far" end of that plank will very probably screw to the stud at the far rear corner of the closet's end wall, which is kind of nice because that hides almost the entire plank.

An alternative, but one that's only suitable if you're definitely never going to hang a lot of clothing from that rod (clothing weight accumulates shockingly quickly), would be to use drywall anchors to attach the rod end mount to the drywall.