First, it is not unconstitutional for the U.S. government to recognize a corporation created by private parties within the District of Columbia, where it has the legislative jurisdiction of a state, as a variety of common law trust, and even to grant it a monopoly on the use of its name. That is not "creation" unless the government is one of the incorporators..
Second, it is not unconstitutional for the U.S. government to enter into a contract with a private bank to receive, hold, and disburse public funds. There is a problem if the contract is not the result of competitive bidding. There is also a potential problem if bank officials exercise governmental functions that are not under a chain of command leading up to an elected official. Executive powers may be delegated but not without supervision of their exercise by the executive branch and the courts.
Third, it would be unconstitutional to forbid a corporation incorporated in one state or territory from conducting business operations in another state or territory, subject only to reasonable regulations or taxes that do not discriminate against out-of-state entities. So the National Bank was certainly within its rights to conduct business in Maryland, and be treated there like a Maryland bank.
Fourth, it would be unconstitutional for Maryland to tax that part of the National Bank that involves the handling of public funds, but not the part that is entirely private. Maryland could reasonably require the Bank to keep accurate books that keep the two sides of its business separated and separately subject to taxation or regulation.
The decision should have been that Maryland may tax the National Bank on its private business on the same basis as it would a Maryland bank, but not on its public business.
All the dictum about "necessary" being merely "convenient" and everything else not needed to reach the above decision should have been omitted.
Read James Madison's notes regarding his objections to Marshall's opinion in McCulloch:
. . . reasoning of Supreme Ct — founded on erroneous views & — 1. as to the ratification of Const: by people if meant people collectively & not by States. 2. imputing concurrence of those formerly opposed to change of opinion, instead of precedents superseding opinion. 3. endeavoring to retain right of Court to pronounce on the consty of law after making Legisl omnipotent as to the expediency of means. 4. expounding power of Congs — as if no other Sovereignty existed in the States supplemental to the enumerated powers of Congs — 5. making the Jud'y — exclusive expositor of the Constitutionality of laws: the co-ordinate authorities Legisl — & Execut — being equally expositors within the scope of their functions.James Madison, Detached Memoranda, reprinted in Writings at 756.