Can I install a subpanel for an electric water heater next to the main panel?
Can you install a sub panel next to a main panel. The answer is yes what it is for is not an issue.
However you have a maxed out panel, a maxed out panel doesn’t mean it can’t be done.  Tankless water heaters are power hogs and your existing panel probably will not have the ampacity to carry the load even understanding a 30 amp 240v breaker will be removed.
I have installed quite a few tankless and for a whole house model a new larger panel is almost always required.
Just a side note you really should talk to several people that have whole house tankless, I had a customer that put a whole house in with a new service then we added point of use electrics in the bathrooms and kitchen he was so unhappy with the unit that he removed the tankless went back to a large tanked electric but kept the point of use electric heaters cost over 10k
I have had multiple customers unhappy with the performance of tankless electrics and I am happy to put them in good $ but don’t like unhappy customers.
Yes you can add a sub but we don’t know if your service is large enough to supply a load this large in addition to your other loads.