There are many economic aspects to the prohibition or legalization of drugs. Let us explore a number of them.
First, there is the impact that your question mentions on the number of prisons and prisoners in the US. If we were to legalize drugs, we would drastically reduce the number of prisons and prisoners in the country. This would have significant economic effects, though it is very hard to know if they would be positive or negative overall. On the negative side, legalization would put huge numbers of prison workers out of jobs. Prisons are often sited in rural areas where there are not that many good jobs. The loss of prison jobs would be negative for those areas. On the other hand, legalization would reduce the amount of taxes that people overall would need to pay to support the prisons and the workers. It is not clear whether the benefits would outweigh the costs.
Second, a similar impact would be had on law enforcement around the country. If law enforcement no longer had to spend resources on trying to enforce drug prohibition, people would not have to pay as much in taxes. On the other hand, legalization might reduce the number of law enforcement officers who would be needed around the country. This would have an economic impact as well.
Finally, legalization would create a huge new legal drug industry. There would be legal drug producers, legal drug transporters, and legal drug sellers. This would provide jobs for many people, thus increasing our economic activity. On the other hand, legalization might deprive many poorer people who do not have much education of “jobs.” Today, many people in the drug “industry” are from poor and uneducated backgrounds. With drugs being legalized, they might no longer have “jobs” because the new, legitimate work would probably go to people from more privileged backgrounds.
All in all, legalization would shift economic resources in many ways. Money would be shifted away from the people who currently try to enforce prohibition and who work in the prison industry. It would also move away from those in the illegal drug trade. It would be moved toward people who could find jobs in the legitimate drug trade and it would be moved back to the people in general in the form of lower taxes. It is not at all possible to know whether these changes would result in a net gain or loss of economic activity overall.