Note: I am not a lawyer; this is not legal advice.
Yes, this seems to be quite legal.
The article What Happens to Inactive Bank Accounts on My Banktracker starts with the warning:
What happens to inactive bank accounts?
If service fees haven’t already drained the balance on the account, an inactive bank account is turned over to the state treasury, where the owner must go in order to retrieve their funds.
It then goes on to explain the steps involved in more detail:
The account is dormant for a specific period of time.
Generally, a time frame of 3 to 5 years with no customer-initiated activity sends an account into dormancy.
The amount of time that must lapse depends on the state in which the bank account was opened.
An attempt is made to contact the account holder.
Before sending the account to the state, the bank must try to notify the account holder.
If the customer does not respond within a certain amount of time, the balance on the account will be turned over to the state.
The bank turns the account over to the state.
In a process what is called “escheating” an account, banks are required to turn over funds from the inactive account to the state treasury.
Once the account is sent to the state, the funds are held as unclaimed property.
To reclaim your money, you will have to contact your state for the instructions on how to get your money back.
This is backed-up by the article What Happens to Dormant Bank Accounts? on The Nest which is more expansive on the subject of fees (emphasis mine):
Dormant bank accounts are still subject to fees, maintenance charges and any other penalties the bank may levy. In the case of checking accounts that typically do not accumulate interest, the fees can erase the balance over time or even put the account in the red. In the case of savings and other interest-earning accounts, the fees can still make a dent, depending on the starting balance. Fees and charges will continue to be assessed until the time when state law deems the account be turned over to the treasury, where the bank no longer has access to the funds.
While this may not "seem fair", from a bank's points-of-view, it is little different from signing up to a cable-TV package or mobile phone contract and then either never turning the TV on or never using your phone. In all three cases, you entered into a contract (with a recurring fee), a facility is made available, and you choose not to use it. In all three cases, the onus is on the user to cancel if they no longer have need of the facility.