Trump's case seems to fall on these grounds since the ones defrauded did not file the lawsuit. Why was it not thrown out on these grounds?
New York State law gives the attorney general the authorization. From Executive (EXC) chapter 18, article 5, section 63, detailing the duties of the attorney general of the State of New York (emphasis by me):
12. Whenever any person shall engage in repeated fraudulent or illegal
acts or otherwise demonstrate persistent fraud or illegality in the
carrying on, conducting or transaction of business, the attorney general may apply, in the name of the people of the state of New York, to the supreme court of the state of New York, on notice of five days, for an
order enjoining the continuance of such business activity or of any
fraudulent or illegal acts, directing restitution and damages and, in an
appropriate case, cancelling any certificate filed under and by virtue
of the provisions of section four hundred forty of the former penal law
or section one hundred thirty of the general business law, and the court
may award the relief applied for or so much thereof as it may deem
proper. The word "fraud" or "fraudulent" as used herein shall include
any device, scheme or artifice to defraud and any deception,
misrepresentation, concealment, suppression, false pretense, false
promise or unconscionable contractual provisions. The term "persistent
fraud" or "illegality" as used herein shall include continuance or
carrying on of any fraudulent or illegal act or conduct. The term
"repeated" as used herein shall include repetition of any separate and
distinct fraudulent or illegal act, or conduct which affects more than
one person. Notwithstanding any law to the contrary, all monies
recovered or obtained under this subdivision by a state agency or state
official or employee acting in their official capacity shall be subject
to subdivision eleven of section four of the state finance law.
In connection with any such application, the attorney general is
authorized to take proof and make a determination of the relevant facts
and to issue subpoenas in accordance with the civil practice law and
rules. Such authorization shall not abate or terminate by reason of any
action or proceeding brought by the attorney general under this section.
The law quoted above gives the attorney general standing to file certain civil fraud suits despite the fact that neither she nor the state of New York was a victim of the fraud. You can think of it as an exception to the normal rules of standing.