Steinbeck needed someone like Curley's wife for his plot. He had the ending in mind before he invented some of the earlier characters and events. He wanted to show a man killing his best friend to save him from being tortured and lynched. The friend had to do something very bad in order to have a lynch mob after him We can sense from the beginning that Lennie is going to get into trouble, and it will probably involve killing something or someone. He was in serious trouble in Weed before they came to the Salinas area. He had been attacking a girl and it was perhaps widely assumed to be an attempted rape, although his interest in her was apparently innocent.
There is plenty of foreshadowing of trouble. Lennie kills things without wanting to do so. He doesn't know his own strength, and he is attracted to small things that are pleasant to pet, including mice, rabbits, and puppies. Naturally he would have to kill a person in order to get into the kind of trouble Steinbeck had in mind for him. Steinbeck invented a wife for Curley who was as young as a wife could be. She was probably only about sixteen. She was too young to realize the friction she was causing with her flirtatious behavior, and too young to understand that Lennie was not a man she ought to get too close to. Since she was young and rather frail, it may have contributed to her neck being broken so easily by being shaken. An older farm woman would not have served the same purpose as a young flirtatious bride.
Curley's wife was just another small, fragile thing that Lennie wanted to pet. Steinbeck invented her to suit his plot. He had her married to Curley because that seemed logical and also because Curley was already going to hate Lennie before his wife was killed. Curley is portrayed as a vicious man. He leads the mob that is coming after Lennie when George decides to shoot his trusting friend himself.
Steinbeck takes pains to give Curley's wife a personality and a background. She reveals a lot about herself to Lennie in the barn just before he accidentally kills her. She is an uneducated small-town girl with a lot of illusions picked up from the movies and romance magazines. The reader may feel some sympathy for her, but Steinbeck didn't want the reader to feel too much compassion because he wanted emotions of that kind pretty much reserved for George and Lennie. If we feel too much pity for the girl, then we couldn't feel much for Lennie when he gets shot. That may have been one of the reasons Steinbeck had for never giving her a name but always referring to her as "Curley's wife." In coninually reminding the reader that she is Curley's wife, it will explain why Curley incites all the men to track Lennie down and lynch him.