Check your condo's bylaws and other documents. Make sure your condo has the right to block the sale. In my area, they generally don't; you can sell to whomever you choose. Now, coops are entirely different. I'm not a lawyer, but...in a condo, you actually own your specific unit, as well as a share of the common elements (lobby, stairs, swimming pool, etc.). And, as an owner, you can sell. In a coop, on the other hand, you own shares in the corporation and your shares give you the right to occupy a specific unit. And coops can (and do) screen and reject buyers.
So, you asked "Is this legal?" It depends on your condo documents. Check with a lawyer.