This is somewhat common and can be done legally. Search for "cram down" or "recapitalizing". It is usually done when a company is about to go bankrupt and a new investor comes in, but wants to clean up that cap table of existing shareholders (who would lose everything if the company went to $0 anyway).
Technically the existing shareholders are asked to agree to the changes as a condition of the new investor(s) putting money in. Sometimes they are given the right to put in money to keep a real position in the newly-recapitalized company.