Since I tend to be ahead in tech most of the time I like to use my spies for counterintelligence, meaning I'll assign them to a city (or district) and leave them to defend it. However, the game regularly asks me to assign them again and the UI for it is actually quite weirdly unwieldy, requiring me to first reassign them to the city and then to the task. Why does this happen and can I somehow teach the game that I want them to stay until I manually command them to do something else?
No this is not possible you have to reassign them every time.
I found that clicking the espionage overview is helpful to avoid making mistakes as it shows where you already have spies assigned - especially if you need to assign two to the same city for protecting different districts.
Updated answer: in newer versions of the game (tested without addons), there is now a button to repeat the previous assignment which makes the process fairly quick and painless compared to before.