Correct me if I am wrong. As it was revealed in the Chamber of Secrets by Tom Riddle, it was Ginny who wrote the blood writings on the wall. Why did she do that? How did Voldemort possess Ginny in the first place? Was it the same thing that happened to Quirrell when he was possessed by Voldemort?
Tom Riddle's diary was a Horcrux - it held a portion of Voldemort's soul. This was revealed later in the series when Horcruxes first became a thing.
From Deathly Hallows, Chapter Six:
"Hang on," said Ron, frowning. "The bit of soul in that diary was possessing Ginny, wasn't it? How does that work, then?"
"While the magical container is still intact, the bit of soul inside it can flit and out of someone if they get too close to the object. I don't mean holding it for too long, it's nothing to do with touching it," [Hermione] added before Ron could speak. "I mean emotionally. Ginny poured her heart out into that diary, she made herself incredibly vulnerable. You're in trouble if you get too fond of or dependent on the Horcrux."
The diary infiltrated her mind and brainwashed her as she communicated with it by writing in it and "reading" the responses. Once she opened herself to it, she became exposed to its influence.
During her first year, she came under the influence of the memory of Tom Riddle's sixteen-year-old self. The memory was preserved in a diary, which forced her to re-open the Chamber of Secrets, endangering the lives of many students, including herself.
In confiding in the diary her deepest fears and secrets, Ginny became increasingly vulnerable to Tom Riddle's memory, which began to pour a little of his own soul back into her and slowly started to influence her. By the start of October, the signs of the influence began to show on Ginny. She started to look peaky, but a spate of colds in the school covered up the true nature of her condition. Her brother Percy forced her to take Pepperup Potion to get her over it. By 31 October, the memory of Tom Riddle was able to take full control of Ginny and used her to open the Chamber of Secrets, releasing its resident monster, the Basilik, which then petrified Argus Filch's cat, Mrs Norris and put all the other students (particularly the Muggle-borns) in great danger.
While I do not have the books available to quote from Chapter Seventeen: The Heir of Slytherin summarizes
Harry finally asks Tom how Ginny got to be in her present state, and Tom smiles broadly and begins to speak.
He tells how Ginny found his diary and poured all of her worries about Hogwarts and her crushes on Harry into it, and how Tom wrote back, comforting her. Through this dialogue, Tom grew stronger and ultimately poured a little of his soul into Ginny, manipulating her to kill Hagrid's roosters and open the Chamber of Secrets. Inside of the diary, Tom explained, he had captured his sixteen- year-old self so that one day, he could lead another to finish the work begun by Slytherin himself. Harry got hold of this diary, delighting Tom, and when Ginny broke into Harry's dorm and stole it back, she had already put so much of herself into the diary that Tom could persuade her to write her own farewell, come down into the Chamber, and allow Tom to leave the pages at last. Tom then begins to question Harry about Voldemort, and Harry grows suspicious and more impatient. Tom then traces the letters of his name, Tom Marvolo Riddle, into the air, and rearranges them to read "I am Lord Voldemort," proclaiming himself the greatest wizard in the world.
Tom Riddle stated that 'I can be very persuasive', and 'she didn't know what she was doing, she was, shall we say, in a trance' Tom Riddle left his diary and Ginny found it. This was when Ginny started writing in it, and Tom Riddle found this was his chance to manipulate her into writing these messages and jumping into the chamber, so he could gain power from her, and she would die
He could possess her since she got so attached to his Horcrux.
The reason that Tom Riddle could possess Ginny Weasley was because of how emotionally close she got to ‘her friend in the diary’, which as he explained, enabled him to possess her.
“If I say it myself, Harry, I’ve always been able to charm the people I needed. So Ginny poured out her soul to me, and her soul happened to be exactly what I wanted. I grew stronger and stronger on a diet of her deepest fears, her darkest secrets. I grew powerful, far more powerful than little Miss Weasley. Powerful enough to start feeding Miss Weasley a few of my secrets, to start pouring a little of my soul back into her …”
- Harry Potter and the Chamber of Secrets, Chapter 17 (The Heir of Slytherin)
This is an ability of the soul piece inside Horcruxes in general - the piece of soul in a Horcrux is able to possess anyone who gets too emotionally close, fond of, or dependent on it.
“Hang on,’ said Ron, frowning. ‘The bit of soul in that diary was possessing Ginny, wasn’t it? How does that work, then?’
‘While the magical container is still intact, the bit of soul inside it can flit in and out of someone if they get too close to the object. I don’t mean holding it for too long, it’s nothing to do with touching it,’ she added, before Ron could speak. ‘I mean close emotionally. Ginny poured her heart out into that diary, she made herself incredibly vulnerable. You’re in trouble if you get too fond of or dependent on the Horcrux.”
- Harry Potter and the Deathly Hallows, Chapter 6 (The Ghoul in Pyjamas)
Since Ginny loved the diary, considered Tom a friend, and told him all her secrets, she got very fond of and emotionally close to the Horcrux, enabling the soul piece inside it to possess her.
Through Tom Riddle's diary, which was a Horcrux.