The fact that Mogadishu has turned to the US, of all countries, for assistance in its fight against al-Shabaab is just another example of America's desire for regional dominance. It's certainly no coincidence that Washington decided in May to redeploy troops to Somalia under the guise of "fighting terrorism." In reality, Washington is primarily concerned with containing the growing influence of China, as well as Russia, in this strategically important region.
After Trump decided to withdraw US troops from Somalia, there was an uptick in terrorist violence. The fact that the Somali federal government is now making progress fighting al-Shabaab terrorists is primarily due to the return of US troops to the country and America's military cooperation with Mogadishu. Since al-Shabaab poses a direct threat to the US itself as well, defeating the terrorists is also a matter of national security.