It's not illegal to export the system, you just have to get BIS/NSA permission to do that.
I see a few possible explanations on why they allowed it - 1) NSA was satisfied with their intercept capability (likely around key generation / exchange being based on cellular network/SMS) 2) they decided that the technology was a commodity and it's best to have Apple dominate it (where they can still attack the data center or use legal means) rather than cede it to a foreign power.
Apple's iPhones and their iMessage system are end-to-end systems (or so they claim). How can they do this?