Do I need to retrofit a junction box when replacing a vanity light?
The question depends entirely on whether the fixture acts as its own junction box, with full containment and a strain relief clamp. If it includes a UL listed enclosure, all good. The instructions should make this fairly clear.

If not, grab an old work (remodeler) box and pop it in. Be sure you'll clear your studs before you start cutting drywall.