Some things in Harry Potter are never really explained. For instance how exactly did Lord Voldemort actually possess Prof. Quirrell?
When bodiless, he could still possess others.
When Voldemort existed in noncorporeal form, he could still possess the bodies of others. He was able to possess animals as well as humans, but as he could not go anywhere he would risk being found, he could not often find humans to possess.
“Only one power remained to me. I could possess the bodies of others. But I dared not go where other humans were plentiful, for I knew that the Aurors were still abroad and searching for me. I sometimes inhabited animals – snakes, of course, being my preference – but I was little better off inside them than as pure spirit, for their bodies were ill-adapted to perform magic … and my possession of them shortened their lives; none of them lasted long …”
- Harry Potter and the Goblet of Fire, Chapter 33 (The Death Eaters)
When Quirrell came across him in the forest, Voldemort was able to possess him the same way he had been possessing animals, as he was at that point pure spirit and had no body of his own to inhabit.
Using magic, presumably. The rough turn of events is:
- Prof. Quirrel travels to Albania. It is said to be for a studying trip, which may be true – or perhaps he already suspected he’d find Voldemort there and was actively seeking him out. This is never explained.
- He comes across Voldemort and ends up joining his cause – whether he was previously sympathetic to the Death Eaters or whether Voldemort managed to bring forth a particularly convincing argument (perhaps tempting him with promises of magical secrets such as immortality) there is not explained.
- He works for a while for Voldemort, still not being possessed.
- He tries (and fails, due to being too late) to steal the Philosophers Stone from Gringotts.
- Voldemort, fed up with Quirrel failing at his job, decides that he needs to monitor and direct him more closely so ends up possessing Quirrel.
The actual mechanism is not really that important. We know that Voldemort at this time is not quite corporeal, but capable of mind control to some extent (he does apparently possess Nagini at some points throughout the story, and later on in GoF we see him inhabit some sort of Homunculus). This is, to put it briefly, just a thing that Voldemort can apparently do.
On a more general note the Harry Potter universe does not really have a hard magic system. Magic can do whatever JKR at a given moment feels like magic ought to be able to do to present something funny or interesting or just for the sheer dramatic convenience. It’s not like there are no rules at all, we know that there are things that are easy to accomplish with magic (making things float, opening locks, producing light), things that are quite difficult to accomplish with magic (transporting people and objects over great distances, healing wounds), things that are just barely possible for a dedicated practitioner in magic to accomplish (unassisted flight, reading minds, creating a philosophers stone) and things that are apparently quite impossible to achieve with magic (truly resurrecting the dead, changing the past). But these are never precisely specified (of course not explicitly, but while there’s an implicit assumption that magic can be narrowed down quite precisely in-universe given that it is taught in a school, there is never a suggestion that we as the audience are to learn the actual rules). Harry Potter Magic isn’t a puzzle you can solve.