She was in exile after murder of Joffrey but then married to Tyrion. After Petyr took her and gave her in marriage to Ramsay, how can this happen?
Petyr "Littlefinger" Baelish explained this while talking to Roose Bolton in the episode "High Sparrow":
BAELISH: (They begin walking). I assure you she's still a virgin. Tyrion never consummated the marriage. By the law of the land, she's no man's wife. Inspect her, if you must.
ROOSE: I leave that to the brothel keeper. It's her name I need, not her virtue.
BAELISH: Then I have delivered everything I've promised.
ROOSE: And you prepared for the consequences. When the Lannisters hear I've wed Sansa Stark to Ramsay...
BAELISH: The Lannister name doesn't mean what it once did. Tywin is dead. He kept his house in power through sheer will. Without him, Jaime has one hand and no allies, Tommen is a soft boy, not a king to fear.
ROOSE: The Queen will be enraged.
BAELISH: Queen Margaery adores Sansa. Cersei is Queen Mother, a title whose importance wanes with each passing day.
The reason that Sansa could still be betrothed to Ramsay Bolton after her marriage to Tyrion Lannister is that he marriage to Tyrion was never consumated. This means that the marriage was never made official in the eyes of the gods, and as such she is free to go on to marry anyone as officially, the marriage never took place.
We see this in one of Sansa's chapters in the A Song of Ice and Fire book A Storm of Swords, or the episode where Sansa is wed to Tyrion in season 3 of Game of Thrones. Tyrion is unable to consumate the marriage as it is clear that Sansa is terrified and unwilling to go through with it. This is confirmed by Petyr Baelish in season 5 of Game of Thrones when he is setting up the wedding between Sansa and Ramsay.