Our verse tells us not to cause anguish to a widow or an orphan. (The Hebrew word yasom is not exactly the same of the English word orphan. A yasom could be someone just without a father. A person with a mother can still be an orphan for the purpose of halacha.) The next verse tells us that if someone dares to cause a widow or an orphan grief, that God promises to Personally step in. If God smites the offender, then that person’s wife will be a widow and his children will be orphans in a very striking case of letting the punishment fit the crime.
The idea behind this mitzvah is similar to the one behind not oppressing converts. Just as the convert has no Jewish family to intercede, a widow has no husband and an orphan has no father. It’s reprehensible for a person to take advantage of such a situation. (Really, one should go to the other extreme and try to help them!)
This mitzvah applies even to oppressing them verbally. However, this doesn’t mean that they can’t be reprimanded or punished if they’ve done something to deserve it. Just the opposite; we wouldn’t want all orphans growing up to be spoiled brats because they could get away with anything they wanted. That would actually be doing them a huge disservice! Rather, a teacher or other appropriate authority figure should admonish them just as they would any other child, but taking it just a little bit easier than they otherwise might.
The obligation to use “kid gloves” with an orphan applies until such a time as the orphan is old enough to handle his own affairs and wouldn’t have to rely on a father figure for help. After that, he’s treated like any other adult.
This prohibition applies to both men and women, in all times and places, and God punishes one sternly for its violation. This mitzvah is codified in the Rambam’s Mishneh Torah in the sixth chapter of Hilchos De’os. To see it in action, look in the Talmudic tractate of Gittin, page 50a and pages 52a-b, as well as elsewhere. It is #256 of the 365 negative mitzvos in the Rambam’s Sefer HaMitzvos and #51 of the 194 negative mitzvos that can be fulfilled today as listed in the Chofetz Chaim’s Sefer HaMitzvos HaKatzar. The Ramban (Nachmanides) counts not oppressing a widow and not oppressing an orphan as two separate mitzvos.