Well, ethics is weaker, when the other is unethical in their own way.
400 euro for a book is hardly ethical. If you must charge that much for a copy you shouldn't have written it because you simply couldn't afford ro write it. Passin your poor business judgement onto others is not ethical.
Prices for scholarly books are not set by the author but by the publisher. The author will often send you a PDF for free if you email and ask nicely.
That's the problem, though. One of my books costs more than $100 USD and that's even on the cheaper side, and as you rightly point out, I had zero choice or saying in the pricing. Some more established authors can influence it, either by publisher choice or by talking with the acquisition editor but that's rare.
The academic book publishing industry is very predatory, which is why so many authors nowadays support open textbook initiatives.
What I can say with certainty is that in many poorer countries scientific research would be impossible without piracy. Universities just don't have the budgets and libraries are often abysmal (unless you work in the capital and it has a prestige state library).
Sorry, I should have said "publish it" instead of "write it".