But then they had a job which Kirk and Sula had no jurisdiction over.
They were there to guard the prisoner. Kirk and sulu were potential threats to that job.
How? Kirk and Sulu were Starfleet officers. The guards were also in Starfleet. Whatever their assignment may have been, they were still subject to the same chain of command that anyone else would be. If an admiral- a highly decorated admiral, no less- asks to visit his friend in a prison cell, there's no reason for a guard to give him attitude about it.
First of all, we can't be sure they are Starfleet personnel. The uniforms are quite different. I think it is more likely they are civilians employed by Starfleet, just as the US Deprtment of Defense employs non-military police and security personnel for its facilites.
Second, militaries have long recognized the "authority of a sentry," that is, if you are ordered to guard a certain place or thing, you have authority over anyone
who enters the space you are responsible for, regardless of their rank, until your CO says otherwise. Can you imagine what would it would be like if anyone of superior rank could come along and change a brig guard's orders?