A soldier was allowed to marry the “beautiful woman” captured in warfare by following the procedure described in the previous mitzvah. If, however, things didn’t work out–such as the soldier deciding he doesn’t want to marry her after the initial attraction has worn off–then he is not allowed to sell her as a slave.
The reason for this mitzvah is the inherent value of every human being. The “beautiful woman” may be an idolator, she may be a citizen of an enemy nation, but she’s still entitled to be treated with human dignity. For the soldier to put the “beautiful woman” through the procedure then to sell her would be lowly and despicable.
This mitzvah only applies when the Jews occupy their land. It is discussed in the Midrash in the Sifre. It is codified in the Mishneh Torah in the eighth chapter of Hilchos Melachim and is #263 of the 365 negative mitzvos in the Rambam’s Sefer HaMitzvos.