When you enter the prison to find the Caged Magistrate in Dragon's Dogma 2, guards will immediately attack you. This is not a bug, as many players thought, but rather reasonable behavior for a guard to see a stranger wandering around a prison. So, how can you stop this?
The Caged Magistrate Quest Walkthrough | A Place with Many Books ► Dragon's Dogma 2
This quest has caused some confusion, because it starts with a guard at the entrance of the prison saying that he is expecting you and that you may enter. But we must understand that only this guard has received instructions from Captain Brant, and that all the others do not know who you are.
If you are attacked, there is nothing stopping you from fighting back and killing the guards, but if you were to survive the fight and leave, you would probably be seen as a criminal by most NPCs in the city from now on. This will lock you out of dialogue and other guards will attack you if you are on the streets. The best way to avoid this is to sneak past the guards in the first place.
Remember to stop at an inn before starting a difficult mission, so you can always return to that safe point if things go wrong.