Stackare means 'poor you' or 'poor him/her/them' and it's a way of expressing sympathy for someone else's troubles. For example “Oj, stackaren!” means “oh no, poor you/him/them/etc”. When it's used in the definitive form, both stackaren and stackarn are heard.
You can also use it in the plural form: de är sjuka, de stackarna (they are sick, the poor things).
It is thought to come from the earlier noun stavkarl (literally meaning 'stick man'), which referred to beggars. Over time, the consonants in the middle got eroded down and the final 'l' was dropped, creating stackare, which also saw its meaning weakened and generalized to refer to anybody in an unfortunate position.
You can also use the adjective stackars, which comes before the noun, name or pronoun (unlike stackaren, you can't use it on its own). For example: stackars djuret (the poor animal), stackars dig (poor you), stackars mig (poor me), stackars henne (poor her), stackars Nils (poor Nils).
As for which contexts are appropriate to use it, stackare and stackars are unlikely to be interpreted as terms of offence, but there is a connotation of helplessness.
So if someone in a position of authority, such as your boss, is telling you about a bad experience, it would be odd to say 'stackars dig!' unless you have a friendly and informal relationship, but if your boss mentions that their children have been ill, it would usually be fine to say 'stackars dem'.
Stackars can also be used to describe more generalized groups and even inanimate objects, and in these cases can take on a meaning similar to 'pitiful', 'sorry', 'unfortunate' or 'wretched'. In these instances, it can sometimes come across as patronizing, so pay close attention to tone and context.
In the dialect of some parts of Dalarna, mainly the orsamål dialect of the Orsa municipality, the word klajte is used instead of stackare.
Den stackaren har fått vinterkräksjukan
The poor thing has caught the winter vomiting virus
Han hade de bästa avsikter och ville bara hjälpa de stackars barnen
He had the best intentions and just wanted to help the poor children