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.
And how were Kirk and Sulu threats to the guards? They didn't take action until they were just about to take McCoy out of the detention area. Yet we have the first guard ordering Kirk around, and the second calls a superior officer a name because of a height difference.