It’s only through a Hufflepuff quest, and only briefly
A few hours into Hogwarts Legacy, you’ll encounter a house-specific questline. All four playable houses have a distinctly different quest that ultimately leads up to their protagonist’s first trip to the Map Chamber, but everything before and after that event will play out roughly the same. Here’s how to visit Azkaban, which is one of those aforementioned house-exclusive quests.
You’ll visit Azkaban as a Hufflepuff through the quest Prisoner of Love
To access Azkaban briefly in a story mission, you’ll need to be sorted into the Hufflepuff house. Every other house will not have the opportunity to visit Azkaban.
After finishing up the Trials of Merlin introduction in the main storyline, you’ll start up a new campaign chapter: Tell Professor Fig about the Map Chamber. That’s your cue that your house-specific storyline is about to begin.
The quest will direct you to a painting of Eldritch Diggory, who will in turn send you north of Hogsmeade to Helen Thislewood: a fellow Auror. After reaching Helen you’ll be presented with a choice to progress the quest further; which involves a brief visit to Azkaban via Apparition (teleporting). In Hogwarts Legacy, Azkaban is not a playable area in multiple respects: it’s not on the world map, and the entire Azkaban sequence itself is a cutscene that lasts roughly five minutes. After several scenes play out, you’ll be apparated back to the main map. And that’s it for Azkaban!
Note that if you’re fishing for the “The Auror’s Apprentice” achievement/trophy, it won’t pop until you actually visit the Map Chamber. You’ll need to finish up Prisoner of Love, and progress through to the “Jackdaw’s Rest” quest. Finish that, open up your talent menu (which unlocks after entering the Map Chamber and finishing the cutscene), and you’ll get the achievement/trophy.