After Vision's death, Wanda traveled to Westview, New Jersey where Vision had apparently bought a plot of land for them. She magicked a house on that land and in the same instance, created the Hex, trapping all of Westview inside it.
Who created the hex WandaVision?
12 Wanda Creates The Hex Involuntarily
Even though Vision died five years before the events of WandaVision, the pain from that death is still fresh for Wanda.
Did Wanda know she created the hex?
Yes, after enough flashbacks to put all the puzzle pieces together Agatha finally figured out Wanda's deal: she had used Chaos Magic to create The Hex in Westview and resurrect Vision, which means she must be the Scarlet Witch.