A large part of the reason arises from the somewhat convoluted history behind the ATF and its affiliation with the Treasury Department. Bear with me while I walk through it a bit.
Enforcement of tax laws and, later, alcohol prohibition, fell under the jurisdiction of the US Treasury Department. As such, it gradually stepped up its investigatory strength over the years until the Bureau of Prohibition was created in 1927. However, the more criminal nature of the Bureau's investigations became apparent and in 1930 it was moved to the Justice Department. Once prohibition ended, however, the Bureau was moved back to the Treasury and returned to its duties as the new Alcohol Tax Unit (ATU) (ATF History Timeline | Bureau of Alcohol, Tobacco, Firearms and Explosives, 2013; Briggs, 2017, pp. 151-2).
In 1934, the National Firearms Act (NFA) was enacted and Congress eventually gave the ATU explicit authority to enforce it (ATF History Timeline | Bureau of Alcohol, Tobacco, Firearms and Explosives, 2013). You may ask, why is ATU/Treasury enforcing a gun control act and not the FBI? Well, because the NFA was enacted primarily as tax legislature. Congress used its authority over tax law to institute its version of gun control, requiring many guns to be heavily taxed upon sale and for all guns to be registered with the Treasury (this latter requirement was repealed in 1968) (ATF National Firearms Act Handbook - Introduction, n.d., p. 1).
This authority eventually grew with the addition of new anti-gun and anti-crime legislation (and the addition of explosives to the ATU's list of responsibilities) and the ATU was renamed the Bureau of Alcohol, Tobacco, and Firearms (ATF) and made a separate agency (but still under the Treasury), all under the same semi-fluid mission of enforcing taxes. Eventually, in 2002, it was brought once again back into the Justice Department (Briggs, 2017, pp. 152).
During this time, additional responsibilities of tracking the sales of explosives (the Explosive Control Act of 1970), and then expanding that to arson (the Anti-Arson Act of 1982) were added as a natural progression of its original tax enforcement mission (Treasury Department - Bureau Of Alcohol, Tobacco, Firearms And Explosives, 2020).
So, while the above may explain how the ATF's mission came to be (essentially, mission creep from tax enforcement), it may not explain well why these agencies continue to be separate to this day. While the 2002 Homeland Security Act did bring them into the DoJ closer to the FBI, there is still a definite case to be made for combining the FBI and ATF to this day. This is most prevalent in the fact that they have collaboration issues stemming an overlapping mission when it comes to gun violence, and that the ATF suffers from budgetary and representation issues from being such a small agency handling such significant responsibilities (Center for American Progress, 2015). The agency's identity crisis and poor leadership have also contributed to extremely low morale (Clark, 2015).
While information is slim on why the agencies are still kept separate, the issue has come up in Congress a few times, including most recently in 2015, and the main arguments against the merger tend to be promoting specialization, de-centralizing law enforcement powers, and a lack of faith that it would solve the underlying problems (Ross, 2015).
ATF History Timeline | Bureau of Alcohol, Tobacco, Firearms and Explosives. (2013). Atf.Gov. https://www.atf.gov/our-history/atf-history-timeline
ATF National Firearms Act Handbook - Introduction. (n.d.).Retrieved from https://www.atf.gov/firearms/docs/undefined/atf-national-firearms-act-handbook-introduction/download.
Briggs, W. (2017). How America got its guns : a history of the gun violence crisis. Albuquerque: University of New Mexico Press.
Center for American Progress. (2015, May). Center for American Progress; Center for American Progress. https://www.americanprogress.org/issues/guns-crime/reports/2015/05/19/111386/the-bureau-and-the-bureau/
Clark, C. S. (2015, May 19). Report: Merge the ATF with the FBI. Government Executive; Government Executive. https://www.govexec.com/management/2015/05/report-merge-atf-fbi/113191/
Ross, J. (2015, June 15). Merging ATF into FBI is a formula for disaster. TheHill. https://thehill.com/blogs/pundits-blog/crime/244958-merging-atf-into-fbi-is-a-formula-for-disaster
Treasury Department - Bureau Of Alcohol, Tobacco, Firearms And Explosives. (2020). Jrank.Org. https://law.jrank.org/pages/10878/Treasury-Department-Bureau-Alcohol-Tobacco-Firearms-Explosives.html