Harrassment is the act of using units to strategically to slow down or stop either the enemies' teching, amassing of units for attack, or economy. Such units are either quick, ranged, and otherwise able to retreat or are heavy units that can survive many encounters while dealing a substantial amount of damage. The ability to retreat is usually used for attacks because harassment is meant to cripple the targets in hit-and-run type attacks and not destroy them completely (although repeated harassment can do this).
Some types of units (such as dark templar) are especially suited to harassment, due to stealth or other reasons (in this case, the ability to infiltrate bases without detection and kill probes or drones in a hit, which does not send a "You are under attack!" warning to the opponent, which means a dark templar can frequently destroy a distracted opponent's economy without the opponent ever knowing what happened).
Harassment is a main part of some strategies as harassment slows down the development of attacking forces which allow players to research, expand, and attack with a stronger force than the other.