It's neither unethical or illegal... and it just happened to one of my buyers and I was ticked.
In my opinion, it's not the best way to handle things. I tell everyone - if I am the listing agent in that case, I talk with my seller and say "Mr. Seller, we have a second offer - a better one - I think we should notify the first people who put in an offer and ask if they want to make any revisions to their offer, to give them an opportunity to make their highest and best offer. In my opinion, it's the best way for us to negotiate a stronger offer for you, and it has the side effect of feeling at least somewhat fair to the buyer." But, not every agent will do that... and not every seller will agree to it. I have had sellers who said "I don't want to mess around with the first people and lose the great offer we now have." As an agent I must obey the wishes of my seller. It's a contractual obligation.
The word "ethical" is thrown around wildly, but as it pertains to REALTORs, we have a strict ethical code, and it is not intuitive.... and that is why I say it is not unethical - I mean, it does not violate the ethical standards of our profession. That does not mean I think it's right or best.
I am sorry that it happened to you. If you love a property, but your best offer out there - if you play games you could lose the property. Even if you're not playing games, if someone else brings a better offer before you have a fully executed contract, well you could still lose the property.