"Afghanistan" is not and never was a coherent country but a tribal region. They could not declare war or peace or time of day !
Next - Bin Laden hid in Afghanistan and was likely aided and abetted by the locals for suitable $$ cash - so the US was quite within their rights of pursuit. Maybe a lawyer would object but this was the practicality of the matter. A Jihadi mind set of the region probably cheered Bin Laden for his successful terrorist attack thus rubbing salt into an open wound.

Try to understand .-)