Why does the US Marines continue to fly the AH-1 Cobra, retired by the US Army in the late 90s?
Well this ain't your father's Cobra.  Literally.

The current incarnation of the Huey cobra for the Marine Corps, which is called the AH-1Z Viper,  sometimes referred to as the King Cobra continues to be the backbone of the Marines attack helicopter force for several reasons.

Like all Huey cobra models, the AH-1Z and the USMC current utility helicopter, the UH-1Y Venom, make use of a common power plant, transmission and rotor set, tailboom and avionics architecture, saving quite a bit on spare parts.  The USMC quotes an 86% commonality between the UH-1Y and AH-1Z airframes.  And, as both the UH-1Y and the AH-1Z constitute a single acquisitions program, it saves a lot of time and costs trying to begin another weapons procurement program for the Corps.  This is also the reason the Huey Cobra even came into existence in the first place.

As helicopters have hit the upper limit in terms of performance, the procurement of a brand new airframe over an existing design doesn't offer many advantages and costs considerably more.  Simply upgrade the engines, add in a modular avionics bay with modern infrastructure facilitating upgrades to modern mission systems and modern weapons, and modern defensive countermeasures systems, and you have help that's as good or better than any existing attack platform out there.

The AH-1Z is comparable to the AH-64 Apache weapons system but remains slightly faster, carries a greater payload and has a 33% greater range than the Apache, all preferred attributes for shipboard operations.