And Kirk isn't responsible for Eminiar's treaties particular since the Federation was never part of those agreements. So any attack on Kirk, his crew or his ship puts him in the right to defend himself.
Probably not, though. If you walk on somebody's lawn, saying "I never signed those STAY OFF THE GRASS signs and never paid for the barbed wire, either", and that somebody punches you, it's you who will get jailed for punching back and hospitalizing the somebody. It's no more self-defense than a bank robber firing at the armed guard who shouts "Freeze!".
Which doesn't change that the Feds knowingly violated a foreign powers' sovereignty out of what was basically laziness and ignored repeated warnings that they'd be in danger if they did enter.
I don't see any laziness there - the Federation very actively breached the borders of the locals with the highly deliberate intent of twisting their hand. They had obviously decided upon all of this beforehand. They just hadn't informed Kirk...
Clearly, the "treaty port" thing was just an excuse, and not something the UFP actually needed in that exact
spot (even if perhaps in that general neck of woods). As per his opening log, Kirk is under the mistaken assumption that he's there to assume friendly relations with random locals (of whom the Eminians and Vendikans are now on the itinerary) - but Fox is there to avenge the Valiant
! note how he tries to stop Kirk from beaming down to hear what the Ambassador will actually be "discussing" with the locals...