A country's military is a reflection of and limited by the society that spawns it. The USA can keep disciplined and ethical soldiers because it has never suffered civil unrest, never been invaded, enjoys prosperity, freedom, public law and justice. No such thing can be said of Afghanistan or Iraq. Moreover - the "10 weeks of BCT" is not "just" "10 weeks of BCT". There is a logistics and supply train several tho-- million pages long that creates those "just" 10 weeks. Consider the fact that humans are recruited. Recruiters need to be trained, fed, paid, and have offices. That costs money. Afghanistan has no money. Consider the fact that young men need to be transported from and to BCT: this requires roads free of IEDs, requires fuel for trucks, favourable economic conditions to produce or import buses. Consider the fact that a certain percentage of all military trainees quit before completing that training. This is accounted for and expected: there are 300 million humans in the USA and this is acceptable losses. Consider the fact that abiding by the laws of a nation and strict adherence to authority is something these "17/18" year olds have done for two decades by the time their military training is over. It is ingrained into their psyche to follow the law from the earliest age, in the most gentle of methods: by the witnessing of safety and prosperity of Americans abiding by the law. Consider an Afghani youth: what is ignrained into them is an invsion by Russia and now invasion by America. How confident in justice do you think they are? How inclined are they to respect authority? How confortable are they submitting to a national government?
A country's military is fundamentally a reflection of the society it spawns. Afghanistan is a failed state in every respect, for the last several decades, and as such it cannot muster a professional military despite the efforts of the US-led coalition.