Emily is trying to ease her loneliness. She wants a husband, or at least, a companion so that she won't have to live her life alone. She is desperate to make the relationship with Homer Barron work, even though everyone else is opposed to it. She doesn't care that he is a Yankee, they go for rides in her carriage, she hopes he will be the one for her. When she discovers that he is unlikely to marry her, she must find a way to make him stay with her.
Emily resorts to murder, she kills Homer Barron and props his dead body on a bed. It is revealed at the end of the story that Emily, more than likely, slept next to the rotting corpse of Homer Barron.
As a sad and lonely woman, she is satisfied to sleep next to a dead body, just so she wouldn't be alone.
When her father died, she was traumatized; she had lived for so long with only him as her closest companion, so his death was a shock to her system. In fact, she is in denial about it for quite some time: "She told them that her father was not dead. She did that for three days, with the ministers calling on her, and the doctors, trying to persuade her to let them dispose of the body. Just as they were about to resort to law and force, she broke down, and they buried her father quickly." Here we see a behavior that she repeats later, which is staunch denial in the face of someone she cares about abandoning her. She repeats this pattern with Homer Barron, who probably denied any possible romantic feelings she had for him, because "he was not the marrying type", and it was hinted that he was gay. When faced with losing yet another man that is going to leave her, she sets about achieving what she truly wants: companionship that will never fail her again. She strives to achieve a way to fill the gap that has existed in her life since her father died. Unfortunately, this striving manifested itself in a rather perverse way, and ended in Homer's unfortunate demise. But, she got her wish, and the iron-gray strand of hair next to his body indicates that she, after all these years, still found some form of comfort in her achievement.