The US invaded and overthrew the Islamic Courts Union in 2006, which was popular and moderate. In the aftermath, the more radical al-Shabaab took over, and now they viewed the US as an enemy. ICU wasn’t great, but they were better than the mess we’re in now.